Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #69 from Ogeon/master
Browse files Browse the repository at this point in the history
Rust updates: vec + slice, read_bytes and inner attributes
  • Loading branch information
chris-morgan committed Mar 30, 2014
2 parents 785e9b4 + 1d3edc5 commit 546f122
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/codegen/branchify.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[macro_escape];
#![macro_escape]

use std::str::Chars;
use std::io::IoResult;
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[crate_id = "codegen"];
#![crate_id = "codegen"]

#[feature(macro_rules)];
#![feature(macro_rules)]

extern crate collections;

Expand Down
4 changes: 2 additions & 2 deletions src/codegen/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/client/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[crate_id = "client"];
#![crate_id = "client"]

extern crate http;
use http::client::RequestWriter;
Expand Down
4 changes: 2 additions & 2 deletions src/examples/server/apache_fake/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//! 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;

use std::vec_ng::Vec;
use std::vec::Vec;

use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::Writer;
Expand Down
4 changes: 1 addition & 3 deletions src/examples/server/hello_world/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! 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;

use std::vec_ng::Vec;

use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::Writer;

Expand Down
4 changes: 1 addition & 3 deletions src/examples/server/info/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! 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;

use std::vec_ng::Vec;

use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::Writer;

Expand Down
4 changes: 2 additions & 2 deletions src/examples/server/request_uri/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//! 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;

use std::vec_ng::Vec;
use std::vec::Vec;

use std::io::net::ip::{SocketAddr, Ipv4Addr};
use std::io::Writer;
Expand Down
6 changes: 3 additions & 3 deletions src/http/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<T: Reader> Reader for BufferedStream<T> {
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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/http/headers/accept_ranges.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/http/headers/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/http/headers/content_type.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
10 changes: 5 additions & 5 deletions src/http/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand All @@ -869,10 +869,10 @@ macro_rules! headers_mod {
} => {
pub mod $mod_name {
//$($attrs;)*
$attr;
#[$attr]
#[allow(unused_imports)];
use std::vec_ng::Vec;
#[allow(unused_imports)]
use std::vec::Vec;
use std::io::IoResult;
use time;
use collections::treemap::{TreeMap, Entries};
Expand Down
7 changes: 3 additions & 4 deletions src/http/headers/serialization_utils.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -217,7 +217,6 @@ pub fn push_parameters<K: Str, V: Str>(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,
Expand Down
2 changes: 1 addition & 1 deletion src/http/headers/transfer_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
20 changes: 10 additions & 10 deletions src/http/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/http/server/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion src/http/server/response.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::vec_ng::Vec;
use std::io::IoResult;
use std::io::net::tcp::TcpStream;

Expand Down

0 comments on commit 546f122

Please sign in to comment.