Merge pull request #403 from hyperium/stabilize

Remove box_syntax and collections feature gates
This commit is contained in:
Sean McArthur
2015-03-27 14:11:38 -07:00
8 changed files with 35 additions and 33 deletions

View File

@@ -57,7 +57,7 @@ impl Request<Fresh> {
let stream = try!(connector.connect(&*host, port, &*url.scheme)); let stream = try!(connector.connect(&*host, port, &*url.scheme));
// FIXME: Use Type ascription // FIXME: Use Type ascription
let stream: Box<NetworkStream + Send> = box stream; let stream: Box<NetworkStream + Send> = Box::new(stream);
let stream = ThroughWriter(BufWriter::new(stream)); let stream = ThroughWriter(BufWriter::new(stream));
let mut headers = Headers::new(); let mut headers = Headers::new();

View File

@@ -130,13 +130,13 @@ mod tests {
status: status::StatusCode::Ok, status: status::StatusCode::Ok,
headers: Headers::new(), headers: Headers::new(),
version: version::HttpVersion::Http11, version: version::HttpVersion::Http11,
body: EofReader(BufReader::new(box MockStream::new())), body: EofReader(BufReader::new(Box::new(MockStream::new()))),
status_raw: RawStatus(200, Borrowed("OK")), status_raw: RawStatus(200, Borrowed("OK")),
_marker: PhantomData, _marker: PhantomData,
}; };
let b = res.into_inner().downcast::<MockStream>().ok().unwrap(); let b = res.into_inner().downcast::<MockStream>().ok().unwrap();
assert_eq!(b, box MockStream::new()); assert_eq!(b, Box::new(MockStream::new()));
} }
@@ -156,7 +156,7 @@ mod tests {
\r\n" \r\n"
); );
let res = Response::new(box stream).unwrap(); let res = Response::new(Box::new(stream)).unwrap();
// The status line is correct? // The status line is correct?
assert_eq!(res.status, status::StatusCode::Ok); assert_eq!(res.status, status::StatusCode::Ok);
@@ -187,7 +187,7 @@ mod tests {
\r\n" \r\n"
); );
let res = Response::new(box stream).unwrap(); let res = Response::new(Box::new(stream)).unwrap();
assert!(read_to_string(res).is_err()); assert!(read_to_string(res).is_err());
} }
@@ -206,7 +206,7 @@ mod tests {
\r\n" \r\n"
); );
let res = Response::new(box stream).unwrap(); let res = Response::new(Box::new(stream)).unwrap();
assert!(read_to_string(res).is_err()); assert!(read_to_string(res).is_err());
} }
@@ -225,7 +225,7 @@ mod tests {
\r\n" \r\n"
); );
let res = Response::new(box stream).unwrap(); let res = Response::new(Box::new(stream)).unwrap();
assert_eq!(read_to_string(res), Ok("1".to_string())); assert_eq!(read_to_string(res), Ok("1".to_string()));
} }

View File

@@ -85,7 +85,7 @@ impl Item {
fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> Option<Box<HeaderFormat + Send + Sync>> { fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> Option<Box<HeaderFormat + Send + Sync>> {
Header::parse_header(&raw[..]).map(|h: H| { Header::parse_header(&raw[..]).map(|h: H| {
// FIXME: Use Type ascription // FIXME: Use Type ascription
let h: Box<HeaderFormat + Send + Sync> = box h; let h: Box<HeaderFormat + Send + Sync> = Box::new(h);
h h
}) })
} }

View File

@@ -356,11 +356,21 @@ mod tests {
use test::Bencher; use test::Bencher;
// Slice.position_elem is unstable
fn index_of(slice: &[u8], byte: u8) -> Option<usize> {
for (index, &b) in slice.iter().enumerate() {
if b == byte {
return Some(index);
}
}
None
}
macro_rules! raw { macro_rules! raw {
($($line:expr),*) => ({ ($($line:expr),*) => ({
[$({ [$({
let line = $line; let line = $line;
let pos = line.position_elem(&b':').expect("raw splits on :, not found"); let pos = index_of(line, b':').expect("raw splits on ':', not found");
httparse::Header { httparse::Header {
name: ::std::str::from_utf8(&line[..pos]).unwrap(), name: ::std::str::from_utf8(&line[..pos]).unwrap(),
value: &line[pos + 2..] value: &line[pos + 2..]

View File

@@ -47,29 +47,29 @@ impl FromStr for EntityTag {
// Early exits: // Early exits:
// 1. The string is empty, or, // 1. The string is empty, or,
// 2. it doesn't terminate in a DQUOTE. // 2. it doesn't terminate in a DQUOTE.
if slice.is_empty() || !slice.ends_with("\"") { if slice.is_empty() || !slice.ends_with('"') {
return Err(()); return Err(());
} }
// The etag is weak if its first char is not a DQUOTE. // The etag is weak if its first char is not a DQUOTE.
if slice.chars().next().unwrap() == '"' /* '"' */ { if slice.starts_with('"') /* '"' */ {
// No need to check if the last char is a DQUOTE, // No need to check if the last char is a DQUOTE,
// we already did that above. // we already did that above.
if check_slice_validity(slice.slice_chars(1, length-1)) { if check_slice_validity(&slice[1..length-1]) {
return Ok(EntityTag { return Ok(EntityTag {
weak: false, weak: false,
tag: slice.slice_chars(1, length-1).to_string() tag: slice[1..length-1].to_string()
}); });
} else { } else {
return Err(()); return Err(());
} }
} }
if slice.slice_chars(0, 3) == "W/\"" { if slice.starts_with("W/\"") {
if check_slice_validity(slice.slice_chars(3, length-1)) { if check_slice_validity(&slice[3..length-1]) {
return Ok(EntityTag { return Ok(EntityTag {
weak: true, weak: true,
tag: slice.slice_chars(3, length-1).to_string() tag: slice[3..length-1].to_string()
}); });
} else { } else {
return Err(()); return Err(());

View File

@@ -1,6 +1,5 @@
#![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")] #![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")]
#![feature(core, collections, io, #![feature(core, io, unsafe_destructor, into_cow, convert)]
box_syntax, unsafe_destructor, into_cow, convert)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
#![cfg_attr(test, feature(alloc, test))] #![cfg_attr(test, feature(alloc, test))]

View File

@@ -355,20 +355,20 @@ mod tests {
#[test] #[test]
fn test_downcast_box_stream() { fn test_downcast_box_stream() {
// FIXME: Use Type ascription // FIXME: Use Type ascription
let stream: Box<NetworkStream + Send> = box MockStream::new(); let stream: Box<NetworkStream + Send> = Box::new(MockStream::new());
let mock = stream.downcast::<MockStream>().ok().unwrap(); let mock = stream.downcast::<MockStream>().ok().unwrap();
assert_eq!(mock, box MockStream::new()); assert_eq!(mock, Box::new(MockStream::new()));
} }
#[test] #[test]
fn test_downcast_unchecked_box_stream() { fn test_downcast_unchecked_box_stream() {
// FIXME: Use Type ascription // FIXME: Use Type ascription
let stream: Box<NetworkStream + Send> = box MockStream::new(); let stream: Box<NetworkStream + Send> = Box::new(MockStream::new());
let mock = unsafe { stream.downcast_unchecked::<MockStream>() }; let mock = unsafe { stream.downcast_unchecked::<MockStream>() };
assert_eq!(mock, box MockStream::new()); assert_eq!(mock, Box::new(MockStream::new()));
} }

View File

@@ -1,6 +1,5 @@
use std::thread::{self, JoinGuard}; use std::thread::{self, JoinGuard};
use std::sync::mpsc; use std::sync::mpsc;
use std::collections::VecMap;
use net::NetworkListener; use net::NetworkListener;
pub struct ListenerPool<A: NetworkListener> { pub struct ListenerPool<A: NetworkListener> {
@@ -24,22 +23,16 @@ impl<'a, A: NetworkListener + Send + 'a> ListenerPool<A> {
let (super_tx, supervisor_rx) = mpsc::channel(); let (super_tx, supervisor_rx) = mpsc::channel();
let counter = &mut 0;
let work = &work; let work = &work;
let mut spawn = move || { let spawn = move |id| {
let id = *counter; spawn_with(super_tx.clone(), work, self.acceptor.clone(), id)
let guard = spawn_with(super_tx.clone(), work, self.acceptor.clone(), id);
*counter += 1;
(id, guard)
}; };
// Go // Go
let mut guards: VecMap<_> = (0..threads).map(|_| spawn()).collect(); let mut guards: Vec<_> = (0..threads).map(|id| spawn(id)).collect();
for id in supervisor_rx.iter() { for id in supervisor_rx.iter() {
guards.remove(&id); guards[id] = spawn(id);
let (id, guard) = spawn();
guards.insert(id, guard);
} }
} }
} }