From 244d772b68e83c4fddf674454e3ac1e49b74e875 Mon Sep 17 00:00:00 2001 From: Erik Hedvall Date: Fri, 21 Mar 2014 10:27:09 +0100 Subject: [PATCH 1/3] Rust update: `std::vec_ng`->`std::vec` and `std::vec`->`std::slice` + removed unused imports --- src/codegen/status.rs | 4 ++-- src/examples/server/apache_fake/main.rs | 2 +- src/examples/server/hello_world/main.rs | 2 -- src/examples/server/info/main.rs | 2 -- src/examples/server/request_uri/main.rs | 2 +- src/http/buffer.rs | 6 +++--- src/http/headers/accept_ranges.rs | 2 +- src/http/headers/connection.rs | 2 +- src/http/headers/content_type.rs | 2 +- src/http/headers/mod.rs | 4 ++-- src/http/headers/serialization_utils.rs | 7 +++---- src/http/headers/transfer_encoding.rs | 2 +- src/http/server/response.rs | 1 - 13 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/codegen/status.rs b/src/codegen/status.rs index f9e0690..b231044 100644 --- a/src/codegen/status.rs +++ b/src/codegen/status.rs @@ -9,7 +9,7 @@ use collections::hashmap::HashSet; use std::ascii::StrAsciiExt; -use std::vec; +use std::slice; use std::io::IoResult; use super::get_writer; @@ -52,7 +52,7 @@ impl Status { /// "ImATeaPot" fn camel_case(msg: &str) -> ~str { let msg = msg.replace("-", " ").replace("'", ""); - let mut result: ~[Ascii] = vec::with_capacity(msg.len()); + let mut result: ~[Ascii] = slice::with_capacity(msg.len()); let mut capitalise = true; for c in msg.chars() { let c = match capitalise { diff --git a/src/examples/server/apache_fake/main.rs b/src/examples/server/apache_fake/main.rs index cecd3d2..f4dad3a 100644 --- a/src/examples/server/apache_fake/main.rs +++ b/src/examples/server/apache_fake/main.rs @@ -7,7 +7,7 @@ extern crate time; extern crate http; -use std::vec_ng::Vec; +use std::vec::Vec; use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer; diff --git a/src/examples/server/hello_world/main.rs b/src/examples/server/hello_world/main.rs index a5ff7ec..3cdb66a 100644 --- a/src/examples/server/hello_world/main.rs +++ b/src/examples/server/hello_world/main.rs @@ -5,8 +5,6 @@ extern crate time; extern crate http; -use std::vec_ng::Vec; - use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer; diff --git a/src/examples/server/info/main.rs b/src/examples/server/info/main.rs index 9d8047f..d1b42be 100644 --- a/src/examples/server/info/main.rs +++ b/src/examples/server/info/main.rs @@ -6,8 +6,6 @@ extern crate time; extern crate http; -use std::vec_ng::Vec; - use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer; diff --git a/src/examples/server/request_uri/main.rs b/src/examples/server/request_uri/main.rs index 1ffd776..4963a47 100644 --- a/src/examples/server/request_uri/main.rs +++ b/src/examples/server/request_uri/main.rs @@ -9,7 +9,7 @@ extern crate time; extern crate http; -use std::vec_ng::Vec; +use std::vec::Vec; use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::Writer; diff --git a/src/http/buffer.rs b/src/http/buffer.rs index 200b89b..039b19b 100644 --- a/src/http/buffer.rs +++ b/src/http/buffer.rs @@ -2,8 +2,8 @@ use std::io::{IoResult, Stream}; use std::cmp::min; -use std::vec_ng::Vec; -use std::vec; +use std::vec::Vec; +use std::slice; use std::num::ToStrRadix; // 64KB chunks (moderately arbitrary) @@ -111,7 +111,7 @@ impl Reader for BufferedStream { try!(self.fill_buffer()); } let size = min(self.read_max - self.read_pos, buf.len()); - vec::bytes::copy_memory(buf, self.read_buffer.slice_from(self.read_pos).slice_to(size)); + slice::bytes::copy_memory(buf, self.read_buffer.slice_from(self.read_pos).slice_to(size)); self.read_pos += size; Ok(size) } diff --git a/src/http/headers/accept_ranges.rs b/src/http/headers/accept_ranges.rs index 44b36b9..a784e65 100644 --- a/src/http/headers/accept_ranges.rs +++ b/src/http/headers/accept_ranges.rs @@ -1,6 +1,6 @@ //! The Accept-Ranges request header, defined in RFC 2616, Section 14.5. -use std::vec_ng::Vec; +use std::vec::Vec; use std::io::IoResult; use std::ascii::StrAsciiExt; diff --git a/src/http/headers/connection.rs b/src/http/headers/connection.rs index bc892f9..1d775ea 100644 --- a/src/http/headers/connection.rs +++ b/src/http/headers/connection.rs @@ -58,7 +58,7 @@ impl super::HeaderConvertible for Connection { #[test] fn test_connection() { - use std::vec_ng::Vec; + use std::vec::Vec; use headers::test_utils::{assert_conversion_correct, assert_interpretation_correct, assert_invalid}; diff --git a/src/http/headers/content_type.rs b/src/http/headers/content_type.rs index 55af084..6dbdf7b 100644 --- a/src/http/headers/content_type.rs +++ b/src/http/headers/content_type.rs @@ -1,6 +1,6 @@ //! The Content-Type entity header, defined in RFC 2616, Section 14.17. use headers::serialization_utils::{push_parameters, WriterUtil}; -use std::vec_ng::Vec; +use std::vec::Vec; use std::io::IoResult; use std::fmt; diff --git a/src/http/headers/mod.rs b/src/http/headers/mod.rs index 4838129..e0160a0 100644 --- a/src/http/headers/mod.rs +++ b/src/http/headers/mod.rs @@ -5,7 +5,7 @@ //! unknown headers are stored in a map in the traditional way. use url::Url; -use std::vec_ng::Vec; +use std::vec::Vec; use std::io::IoResult; use time::{Tm, strptime}; use rfc2616::{is_token_item, is_separator, CR, LF, SP, HT, COLON}; @@ -872,7 +872,7 @@ macro_rules! headers_mod { $attr; #[allow(unused_imports)]; - use std::vec_ng::Vec; + use std::vec::Vec; use std::io::IoResult; use time; use collections::treemap::{TreeMap, Entries}; diff --git a/src/http/headers/serialization_utils.rs b/src/http/headers/serialization_utils.rs index c3ac7fd..7c37181 100644 --- a/src/http/headers/serialization_utils.rs +++ b/src/http/headers/serialization_utils.rs @@ -1,7 +1,7 @@ //! Utility functions for assisting with conversion of headers from and to the HTTP text form. -use std::vec_ng::Vec; -use std::vec; +use std::vec::Vec; +use std::slice; use std::ascii::Ascii; use std::io::IoResult; use rfc2616::is_token; @@ -23,7 +23,7 @@ use rfc2616::is_token; /// assert_eq!(normalise_header_name("FOO-BAR"), "Foo-Bar"); /// ~~~ pub fn normalise_header_name(name: &str) -> ~str { - let mut result: ~[Ascii] = vec::with_capacity(name.len()); + let mut result: ~[Ascii] = slice::with_capacity(name.len()); let mut capitalise = true; for c in name.chars() { let c = match capitalise { @@ -217,7 +217,6 @@ pub fn push_parameters(mut s: ~str, parameters: &[(K, V)]) -> ~s #[cfg(test)] mod test { - use std::vec_ng::Vec; use super::{normalise_header_name, comma_split, comma_split_iter, comma_join, push_quality, push_parameter, push_parameters, push_maybe_quoted_string, push_quoted_string, maybe_quoted_string, quoted_string, diff --git a/src/http/headers/transfer_encoding.rs b/src/http/headers/transfer_encoding.rs index c92dbd3..7bb3668 100644 --- a/src/http/headers/transfer_encoding.rs +++ b/src/http/headers/transfer_encoding.rs @@ -2,7 +2,7 @@ //! //! Transfer-Encoding = "Transfer-Encoding" ":" 1#transfer-coding -use std::vec_ng::Vec; +use std::vec::Vec; use std::ascii::StrAsciiExt; use std::io::IoResult; use headers::serialization_utils::{WriterUtil, push_parameters}; diff --git a/src/http/server/response.rs b/src/http/server/response.rs index 16a23f5..4ca9ee7 100644 --- a/src/http/server/response.rs +++ b/src/http/server/response.rs @@ -1,4 +1,3 @@ -use std::vec_ng::Vec; use std::io::IoResult; use std::io::net::tcp::TcpStream; From 83cd488b164074ed5dc09be8c5989d5a04a6d8ed Mon Sep 17 00:00:00 2001 From: Erik Hedvall Date: Sun, 30 Mar 2014 13:20:57 +0200 Subject: [PATCH 2/3] Rust update: `TcpStream::read_bytes` -> `TcpStream::read_exact` --- src/http/server/request.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http/server/request.rs b/src/http/server/request.rs index 336a914..8f14b22 100644 --- a/src/http/server/request.rs +++ b/src/http/server/request.rs @@ -372,7 +372,7 @@ impl Request { // Read body if its length is specified match request.headers.content_length { Some(length) => { - match buffer.read_bytes(length) { + match buffer.read_exact(length) { Ok(body) => match str::from_utf8(body) { Some(body_str) => request.body = body_str.to_owned(), None => return (request, Err(status::BadRequest)) From 1d3edc54b7c6930d708a5bb81619bb1840ec5066 Mon Sep 17 00:00:00 2001 From: Erik Hedvall Date: Sun, 30 Mar 2014 13:23:19 +0200 Subject: [PATCH 3/3] Rust update: Switched to the new inner macro syntax, with a quick fix for the `headers_mod` macro --- src/codegen/branchify.rs | 2 +- src/codegen/main.rs | 4 ++-- src/examples/client/main.rs | 2 +- src/examples/server/apache_fake/main.rs | 2 +- src/examples/server/hello_world/main.rs | 2 +- src/examples/server/info/main.rs | 2 +- src/examples/server/request_uri/main.rs | 2 +- src/http/headers/mod.rs | 6 +++--- src/http/lib.rs | 20 ++++++++++---------- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/codegen/branchify.rs b/src/codegen/branchify.rs index 8d85241..27d6965 100644 --- a/src/codegen/branchify.rs +++ b/src/codegen/branchify.rs @@ -1,4 +1,4 @@ -#[macro_escape]; +#![macro_escape] use std::str::Chars; use std::io::IoResult; diff --git a/src/codegen/main.rs b/src/codegen/main.rs index 8faeb00..59433b0 100644 --- a/src/codegen/main.rs +++ b/src/codegen/main.rs @@ -1,6 +1,6 @@ -#[crate_id = "codegen"]; +#![crate_id = "codegen"] -#[feature(macro_rules)]; +#![feature(macro_rules)] extern crate collections; diff --git a/src/examples/client/main.rs b/src/examples/client/main.rs index 6b58a3d..f692589 100644 --- a/src/examples/client/main.rs +++ b/src/examples/client/main.rs @@ -1,4 +1,4 @@ -#[crate_id = "client"]; +#![crate_id = "client"] extern crate http; use http::client::RequestWriter; diff --git a/src/examples/server/apache_fake/main.rs b/src/examples/server/apache_fake/main.rs index f4dad3a..8f8be1f 100644 --- a/src/examples/server/apache_fake/main.rs +++ b/src/examples/server/apache_fake/main.rs @@ -2,7 +2,7 @@ //! configuration. Potentially useful for a smidgeon of performance comparison, though naturally //! Apache is doing a lot more than this does. -#[crate_id = "apache_fake"]; +#![crate_id = "apache_fake"] extern crate time; extern crate http; diff --git a/src/examples/server/hello_world/main.rs b/src/examples/server/hello_world/main.rs index 3cdb66a..3034ce2 100644 --- a/src/examples/server/hello_world/main.rs +++ b/src/examples/server/hello_world/main.rs @@ -1,6 +1,6 @@ //! A very simple HTTP server which responds with the plain text "Hello, World!" to every request. -#[crate_id = "hello_world"]; +#![crate_id = "hello_world"] extern crate time; extern crate http; diff --git a/src/examples/server/info/main.rs b/src/examples/server/info/main.rs index d1b42be..e835642 100644 --- a/src/examples/server/info/main.rs +++ b/src/examples/server/info/main.rs @@ -1,7 +1,7 @@ //! A not-quite-trivial HTTP server which responds to requests by showing the request and response //! headers and any other information it has. -#[crate_id = "info"]; +#![crate_id = "info"] extern crate time; extern crate http; diff --git a/src/examples/server/request_uri/main.rs b/src/examples/server/request_uri/main.rs index 4963a47..174a1e7 100644 --- a/src/examples/server/request_uri/main.rs +++ b/src/examples/server/request_uri/main.rs @@ -4,7 +4,7 @@ //! This demonstrates some handling of the RequestURI, which has several possibilities and for which //! the correct values depend on the method. -#[crate_id = "request_uri"]; +#![crate_id = "request_uri"] extern crate time; extern crate http; diff --git a/src/http/headers/mod.rs b/src/http/headers/mod.rs index e0160a0..d52b83d 100644 --- a/src/http/headers/mod.rs +++ b/src/http/headers/mod.rs @@ -853,7 +853,7 @@ mod test { macro_rules! headers_mod { { - $attr:attr + #[$attr:meta] // Not using this because of a "local ambiguity" bug //$($attrs:attr)* pub mod $mod_name:ident; @@ -869,9 +869,9 @@ macro_rules! headers_mod { } => { pub mod $mod_name { //$($attrs;)* - $attr; + #[$attr] - #[allow(unused_imports)]; + #[allow(unused_imports)] use std::vec::Vec; use std::io::IoResult; use time; diff --git a/src/http/lib.rs b/src/http/lib.rs index 5e4a5a8..c2d07ce 100644 --- a/src/http/lib.rs +++ b/src/http/lib.rs @@ -1,18 +1,18 @@ -#[crate_id = "http#0.1-pre"]; +#![crate_id = "http#0.1-pre"] -#[comment = "Rust HTTP server"]; -#[license = "MIT/ASL2"]; -#[crate_type = "dylib"]; -#[crate_type = "rlib"]; +#![comment = "Rust HTTP server"] +#![license = "MIT/ASL2"] +#![crate_type = "dylib"] +#![crate_type = "rlib"] -#[doc(html_root_url = "http://www.rust-ci.org/chris-morgan/rust-http/doc/")]; +#![doc(html_root_url = "http://www.rust-ci.org/chris-morgan/rust-http/doc/")] -#[deny(non_camel_case_types)]; +#![deny(non_camel_case_types)] //#[deny(missing_doc)]; -#[feature(macro_rules)]; -#[feature(phase)]; -#[macro_escape]; +#![feature(macro_rules)] +#![feature(phase)] +#![macro_escape] #[phase(syntax, link)] extern crate log; extern crate url;