update str::from_utf8
This commit is contained in:
		| @@ -19,6 +19,8 @@ typeable = "*" | |||||||
| cookie = "*" | cookie = "*" | ||||||
| time = "*" | time = "*" | ||||||
| mucell = "*" | mucell = "*" | ||||||
|  | log = "*" | ||||||
|  | rustc-serialize = "*" | ||||||
|  |  | ||||||
| [dev-dependencies] | [dev-dependencies] | ||||||
| curl = "*" | curl = "*" | ||||||
|   | |||||||
| @@ -34,7 +34,7 @@ impl Header for Accept { | |||||||
|         let mut mimes: Vec<Mime> = vec![]; |         let mut mimes: Vec<Mime> = vec![]; | ||||||
|         for mimes_raw in raw.iter() { |         for mimes_raw in raw.iter() { | ||||||
|             match from_utf8(mimes_raw.as_slice()) { |             match from_utf8(mimes_raw.as_slice()) { | ||||||
|                 Some(mimes_str) => { |                 Ok(mimes_str) => { | ||||||
|                     for mime_str in mimes_str.split(',') { |                     for mime_str in mimes_str.split(',') { | ||||||
|                         match from_str(mime_str.trim()) { |                         match from_str(mime_str.trim()) { | ||||||
|                             Some(mime) => mimes.push(mime), |                             Some(mime) => mimes.push(mime), | ||||||
| @@ -42,7 +42,7 @@ impl Header for Accept { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 }, |                 }, | ||||||
|                 None => return None |                 Err(_) => return None | ||||||
|             }; |             }; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -27,11 +27,11 @@ impl<S: Scheme> Header for Authorization<S> { | |||||||
|     fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> { |     fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> { | ||||||
|         if raw.len() == 1 { |         if raw.len() == 1 { | ||||||
|             match (from_utf8(unsafe { raw[].unsafe_get(0)[] }), Scheme::scheme(None::<S>)) { |             match (from_utf8(unsafe { raw[].unsafe_get(0)[] }), Scheme::scheme(None::<S>)) { | ||||||
|                 (Some(header), Some(scheme)) |                 (Ok(header), Some(scheme)) | ||||||
|                     if header.starts_with(scheme) && header.len() > scheme.len() + 1 => { |                     if header.starts_with(scheme) && header.len() > scheme.len() + 1 => { | ||||||
|                     from_str::<S>(header[scheme.len() + 1..]).map(|s| Authorization(s)) |                     from_str::<S>(header[scheme.len() + 1..]).map(|s| Authorization(s)) | ||||||
|                 }, |                 }, | ||||||
|                 (Some(header), None) => from_str::<S>(header).map(|s| Authorization(s)), |                 (Ok(header), None) => from_str::<S>(header).map(|s| Authorization(s)), | ||||||
|                 _ => None |                 _ => None | ||||||
|             } |             } | ||||||
|         } else { |         } else { | ||||||
|   | |||||||
| @@ -27,7 +27,7 @@ impl Header for Cookies { | |||||||
|         let mut cookies = Vec::with_capacity(raw.len()); |         let mut cookies = Vec::with_capacity(raw.len()); | ||||||
|         for cookies_raw in raw.iter() { |         for cookies_raw in raw.iter() { | ||||||
|             match from_utf8(cookies_raw[]) { |             match from_utf8(cookies_raw[]) { | ||||||
|                 Some(cookies_str) => { |                 Ok(cookies_str) => { | ||||||
|                     for cookie_str in cookies_str.split(';') { |                     for cookie_str in cookies_str.split(';') { | ||||||
|                         match from_str(cookie_str.trim()) { |                         match from_str(cookie_str.trim()) { | ||||||
|                             Some(cookie) => cookies.push(cookie), |                             Some(cookie) => cookies.push(cookie), | ||||||
| @@ -35,7 +35,7 @@ impl Header for Cookies { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 }, |                 }, | ||||||
|                 None => return None |                 Err(_) => return None | ||||||
|             }; |             }; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ impl Header for SetCookie { | |||||||
|         let mut set_cookies = Vec::with_capacity(raw.len()); |         let mut set_cookies = Vec::with_capacity(raw.len()); | ||||||
|         for set_cookies_raw in raw.iter() { |         for set_cookies_raw in raw.iter() { | ||||||
|             match from_utf8(set_cookies_raw[]) { |             match from_utf8(set_cookies_raw[]) { | ||||||
|                 Some(s) if !s.is_empty() => { |                 Ok(s) if !s.is_empty() => { | ||||||
|                     match from_str(s) { |                     match from_str(s) { | ||||||
|                         Some(cookie) => set_cookies.push(cookie), |                         Some(cookie) => set_cookies.push(cookie), | ||||||
|                         None => () |                         None => () | ||||||
|   | |||||||
| @@ -11,8 +11,8 @@ pub fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> { | |||||||
|     } |     } | ||||||
|     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. |     // we JUST checked that raw.len() == 1, so raw[0] WILL exist. | ||||||
|     match from_utf8(unsafe { raw[].unsafe_get(0)[] }) { |     match from_utf8(unsafe { raw[].unsafe_get(0)[] }) { | ||||||
|         Some(s) => FromStr::from_str(s), |         Ok(s) => FromStr::from_str(s), | ||||||
|         None => None |         Err(_) => None | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -29,13 +29,13 @@ pub fn from_comma_delimited<T: FromStr>(raw: &[Vec<u8>]) -> Option<Vec<T>> { | |||||||
| /// Reads a comma-delimited raw string into a Vec. | /// Reads a comma-delimited raw string into a Vec. | ||||||
| pub fn from_one_comma_delimited<T: FromStr>(raw: &[u8]) -> Option<Vec<T>> { | pub fn from_one_comma_delimited<T: FromStr>(raw: &[u8]) -> Option<Vec<T>> { | ||||||
|     match from_utf8(raw) { |     match from_utf8(raw) { | ||||||
|         Some(s) => { |         Ok(s) => { | ||||||
|             Some(s.as_slice() |             Some(s.as_slice() | ||||||
|                  .split([',', ' '].as_slice()) |                  .split([',', ' '].as_slice()) | ||||||
|                  .filter_map(from_str) |                  .filter_map(from_str) | ||||||
|                  .collect()) |                  .collect()) | ||||||
|         } |         } | ||||||
|         None => None |         Err(_) => None | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ use std::intrinsics::TypeId; | |||||||
| use std::raw::TraitObject; | use std::raw::TraitObject; | ||||||
| use std::str::{SendStr, FromStr}; | use std::str::{SendStr, FromStr}; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| use std::collections::hash_map::{Entries, Occupied, Vacant}; | use std::collections::hash_map::{Entries, Entry}; | ||||||
| use std::{hash, mem}; | use std::{hash, mem}; | ||||||
|  |  | ||||||
| use mucell::MuCell; | use mucell::MuCell; | ||||||
| @@ -130,8 +130,8 @@ impl Headers { | |||||||
|                     debug!("raw header: {}={}", name, value[].to_ascii()); |                     debug!("raw header: {}={}", name, value[].to_ascii()); | ||||||
|                     let name = CaseInsensitive(Owned(name)); |                     let name = CaseInsensitive(Owned(name)); | ||||||
|                     let mut item = match headers.data.entry(name) { |                     let mut item = match headers.data.entry(name) { | ||||||
|                         Vacant(entry) => entry.set(MuCell::new(Item::raw(vec![]))), |                         Entry::Vacant(entry) => entry.set(MuCell::new(Item::raw(vec![]))), | ||||||
|                         Occupied(entry) => entry.into_mut() |                         Entry::Occupied(entry) => entry.into_mut() | ||||||
|                     }; |                     }; | ||||||
|  |  | ||||||
|                     match &mut item.borrow_mut().raw { |                     match &mut item.borrow_mut().raw { | ||||||
|   | |||||||
| @@ -622,7 +622,7 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> { | |||||||
|         try!(stream.read_byte()), |         try!(stream.read_byte()), | ||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|     let code = match str::from_utf8(code.as_slice()).and_then(from_str::<u16>) { |     let code = match str::from_utf8(code.as_slice()).ok().and_then(from_str::<u16>) { | ||||||
|         Some(num) => num, |         Some(num) => num, | ||||||
|         None => return Err(HttpStatusError) |         None => return Err(HttpStatusError) | ||||||
|     }; |     }; | ||||||
| @@ -662,8 +662,8 @@ pub fn read_status<R: Reader>(stream: &mut R) -> HttpResult<RawStatus> { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     let reason = match str::from_utf8(buf[]) { |     let reason = match str::from_utf8(buf[]) { | ||||||
|         Some(s) => s.trim(), |         Ok(s) => s.trim(), | ||||||
|         None => return Err(HttpStatusError) |         Err(_) => return Err(HttpStatusError) | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     let reason = match from_u16::<StatusCode>(code) { |     let reason = match from_u16::<StatusCode>(code) { | ||||||
|   | |||||||
| @@ -125,7 +125,7 @@ | |||||||
| //! implement `Reader` and can be read to get the data out of a `Response`. | //! implement `Reader` and can be read to get the data out of a `Response`. | ||||||
| //! | //! | ||||||
|  |  | ||||||
| extern crate serialize; | extern crate "rustc-serialize" as serialize; | ||||||
| extern crate time; | extern crate time; | ||||||
| extern crate url; | extern crate url; | ||||||
| extern crate openssl; | extern crate openssl; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user