Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context/maybe_utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<S, V> MaybeUtf8<S, V> {
///let string = MaybeUtf8Owned::from("abc");
///assert_eq!(Some("abc"), string.as_utf8());
///```
pub fn as_utf8<'a>(&'a self) -> Option<&'a str> where S: AsRef<str> {
pub fn as_utf8(&self) -> Option<&str> where S: AsRef<str> {
match *self {
MaybeUtf8::Utf8(ref s) => Some(s.as_ref()),
MaybeUtf8::NotUtf8(_) => None
Expand Down
4 changes: 2 additions & 2 deletions src/context/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Parameters {
T: FromStr
{
if let Some(val) = self.0.get(key.as_ref()) {
val.as_utf8_lossy().parse().map_err(|e| Some(e))
val.as_utf8_lossy().parse().map_err(Some)
} else {
Err(None)
}
Expand Down Expand Up @@ -230,4 +230,4 @@ impl<K: Into<MaybeUtf8Owned>, V: Into<MaybeUtf8Owned>> Extend<(K, V)> for Parame
fn extend<T: IntoIterator<Item=(K, V)>>(&mut self, iter: T) {
self.0.extend(iter.into_iter().map(|(k, v)| (k.into(), v.into())))
}
}
}
28 changes: 14 additions & 14 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ pub enum Data<'a> {
impl<'a> Data<'a> {
///Borrow the content as a byte slice.
pub fn as_bytes(&self) -> &[u8] {
match self {
&Data::Bytes(ref bytes) => bytes,
&Data::String(ref string) => string.as_bytes(),
match *self {
Data::Bytes(ref bytes) => bytes,
Data::String(ref string) => string.as_bytes(),
}
}

Expand All @@ -213,9 +213,9 @@ impl<'a> Data<'a> {

///Borrow the content as a UTF-8 string slice, if possible.
pub fn as_string(&self) -> Result<&str, Utf8Error> {
match self {
&Data::Bytes(ref bytes) => from_utf8(bytes),
&Data::String(ref string) => Ok(string),
match *self {
Data::Bytes(ref bytes) => from_utf8(bytes),
Data::String(ref string) => Ok(string),
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ impl<'a> Into<Data<'a>> for &'a str {
///its size is known.
pub struct Response<'a, 'b> {
writer: Option<hyper::server::response::Response<'a>>,
filters: &'b Vec<Box<ResponseFilter>>,
filters: &'b [Box<ResponseFilter>],
global: &'b Global,
filter_storage: Option<AnyMap>,
force_close: bool
Expand All @@ -271,7 +271,7 @@ impl<'a, 'b> Response<'a, 'b> {
///Internal and may change without warning.
pub fn new(
response: hyper::server::response::Response<'a>,
filters: &'b Vec<Box<ResponseFilter>>,
filters: &'b [Box<ResponseFilter>],
global: &'b Global,
force_close: bool
) -> Response<'a, 'b> {
Expand Down Expand Up @@ -537,14 +537,14 @@ impl<'a, 'b> Response<'a, 'b> {

let mut writer = unsafe { self.into_raw(metadata.len()) };

io::copy(&mut file, &mut writer).map_err(|e| FileError::Send(e)).map(|_| ())
io::copy(&mut file, &mut writer).map_err(FileError::Send).map(|_| ())
}

///Write the status code and headers to the client and turn the `Response`
///into a `Chunked` response.
pub fn into_chunked(mut self) -> Chunked<'a, 'b> {
let mut writer = self.writer.take().expect("response used after drop");

//Make sure it's chunked
writer.headers_mut().remove::<::header::ContentLength>();
writer.headers_mut().remove_raw("content-length");
Expand Down Expand Up @@ -621,7 +621,7 @@ impl<'a, 'b> Drop for Response<'a, 'b> {
///an overhead for each time `send` or `try_send` is called (simply put).
pub struct Chunked<'a, 'b> {
writer: Option<Result<hyper::server::response::Response<'a, hyper::net::Streaming>, Error>>,
filters: &'b Vec<Box<ResponseFilter>>,
filters: &'b [Box<ResponseFilter>],
global: &'b Global,
filter_storage: AnyMap
}
Expand Down Expand Up @@ -738,7 +738,7 @@ impl<'a, 'b> Chunked<'a, 'b> {
}
}

writer.end().map_err(|e| Error::Io(e))
writer.end().map_err(Error::Io)
}

fn borrow_writer(&mut self) -> Result<&mut hyper::server::response::Response<'a, hyper::net::Streaming>, Error> {
Expand Down Expand Up @@ -982,8 +982,8 @@ fn filter_end<'a>(filters: &'a [Box<ResponseFilter>], global: &Global, filter_st

filter.end(filter_context)
})
.take_while(|a| if let &Action::Next(_) = a { true } else { false })
.map(|a| Some(a))
.take_while(|a| if let Action::Next(_) = *a { true } else { false })
.map(Some)
.collect();

let mut write_queue = vec![];
Expand Down
12 changes: 6 additions & 6 deletions src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ impl<I: Iterator> Iterator for RouteIter<I> {
type Item = <I as Iterator>::Item;

fn next(&mut self) -> Option<<Self as Iterator>::Item> {
match self {
&mut RouteIter::Path(ref mut i) => i.next(),
&mut RouteIter::Root => None
match *self {
RouteIter::Path(ref mut i) => i.next(),
RouteIter::Root => None
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
match self {
&RouteIter::Path(ref i) => i.size_hint(),
&RouteIter::Root => (0, Some(0))
match *self {
RouteIter::Path(ref i) => i.size_hint(),
RouteIter::Root => (0, Some(0))
}
}
}
10 changes: 5 additions & 5 deletions src/router/tree_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a, I: Iterator<Item=(usize, &'a [u8])>> Iterator for VariableIter<'a, I> {
type Item=(MaybeUtf8Owned, MaybeUtf8Owned);

fn next(&mut self) -> Option<Self::Item> {
while let Some((next_index, next_segment)) = self.iter.next() {
for (next_index, next_segment) in &mut self.iter {
//validate next_index and check if the variable has a name
debug_assert!(next_index < self.names.len(), format!("invalid variable name index! variable_names.len(): {}, index: {}", self.names.len(), next_index));
let next_name = match self.names.get(next_index) {
Expand Down Expand Up @@ -226,14 +226,14 @@ impl<T: Handler> Router for TreeRouter<T> {
let path = route.segments().collect::<Vec<_>>();
let mut variables = vec![None; path.len()];
let mut stack = vec![(self, Wildcard, 0, 0), (self, Variable, 0, 0), (self, Static, 0, 0)];

let mut result: Endpoint<T> = None.into();

while let Some((current, branch, index, var_index)) = stack.pop() {
if index == path.len() && result.handler.is_none() {
if let Some(&(ref item, ref variable_names)) = current.items.get(&method) {
let values = path.iter().zip(variables.iter()).filter_map(|(v, keep)| {
if let &Some(index) = keep {
if let Some(index) = *keep {
Some((index, v.clone()))
} else {
None
Expand Down Expand Up @@ -438,7 +438,7 @@ mod test {
use context::MaybeUtf8Slice;

let handler: Option<&str> = $handler;
let handler = handler.map(|h| TestHandler::from(h));
let handler = handler.map(TestHandler::from);
let mut endpoint = $res;
assert_eq!(endpoint.handler, handler.as_ref());
let expected_vars: HashMap<MaybeUtf8Slice, MaybeUtf8Slice> = map!($($key => $val),*);
Expand Down Expand Up @@ -882,4 +882,4 @@ mod test {
counter = (counter + 1) % paths.len()
});
}
}
}
2 changes: 1 addition & 1 deletion src/server/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl FromStr for Host {
type Err = <SocketAddr as FromStr>::Err;

fn from_str(s: &str) -> Result<Host, Self::Err> {
s.parse().map(|s| Host(s))
s.parse().map(Host)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/server/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ impl<R: Router> HyperHandler for ServerInstance<R> {
ContextAction::Next => {
*response.filter_storage_mut() = filter_storage;

let endpoint = context.uri.as_path().map(|path| self.handlers.find(&context.method, &path)).unwrap_or_else(|| {
let endpoint = context.uri.as_path().map_or_else(|| {
Endpoint {
handler: None,
variables: HashMap::new(),
hyperlinks: vec![]
}
});
}, |path| self.handlers.find(&context.method, &path));

let Endpoint {
handler,
Expand Down Expand Up @@ -298,7 +298,7 @@ fn parse_path(path: &str) -> ParsedUri {
}
}

fn parse_fragment<'a>(path: &'a str) -> (&'a str, Option<&'a str>) {
fn parse_fragment(path: &str) -> (&str, Option<&str>) {
match path.find('#') {
Some(index) => (&path[..index], Some(&path[index+1..])),
None => (path, None)
Expand All @@ -316,7 +316,7 @@ fn parse_url(url: Url) -> ParsedUri {
}

let query = url.query_pairs()
.unwrap_or_else(|| Vec::new())
.unwrap_or_default()
.into_iter()
.collect();

Expand Down