fix(rustup): update FromStr
Signed-off-by: Peter Atashian <retep998@gmail.com>
This commit is contained in:
committed by
Sean McArthur
parent
c983ebf3ce
commit
742081c8cf
@@ -32,9 +32,9 @@ impl<S: Scheme> Header for Authorization<S> {
|
||||
match (from_utf8(unsafe { &raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
|
||||
(Ok(header), Some(scheme))
|
||||
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
|
||||
header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s))
|
||||
header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s)).ok()
|
||||
},
|
||||
(Ok(header), None) => header.parse::<S>().map(|s| Authorization(s)),
|
||||
(Ok(header), None) => header.parse::<S>().map(|s| Authorization(s)).ok(),
|
||||
_ => None
|
||||
}
|
||||
} else {
|
||||
@@ -108,32 +108,33 @@ impl Scheme for Basic {
|
||||
}
|
||||
|
||||
impl FromStr for Basic {
|
||||
fn from_str(s: &str) -> Option<Basic> {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Basic, ()> {
|
||||
match s.from_base64() {
|
||||
Ok(decoded) => match String::from_utf8(decoded) {
|
||||
Ok(text) => {
|
||||
let mut parts = &mut text[].split(':');
|
||||
let user = match parts.next() {
|
||||
Some(part) => part.to_string(),
|
||||
None => return None
|
||||
None => return Err(())
|
||||
};
|
||||
let password = match parts.next() {
|
||||
Some(part) => Some(part.to_string()),
|
||||
None => None
|
||||
};
|
||||
Some(Basic {
|
||||
Ok(Basic {
|
||||
username: user,
|
||||
password: password
|
||||
})
|
||||
},
|
||||
Err(e) => {
|
||||
debug!("Basic::from_utf8 error={:?}", e);
|
||||
None
|
||||
Err(())
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
debug!("Basic::from_base64 error={:?}", e);
|
||||
None
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,28 +96,29 @@ impl fmt::Display for CacheDirective {
|
||||
}
|
||||
|
||||
impl FromStr for CacheDirective {
|
||||
fn from_str(s: &str) -> Option<CacheDirective> {
|
||||
type Err = Option<<u32 as FromStr>::Err>;
|
||||
fn from_str(s: &str) -> Result<CacheDirective, Option<<u32 as FromStr>::Err>> {
|
||||
use self::CacheDirective::*;
|
||||
match s {
|
||||
"no-cache" => Some(NoCache),
|
||||
"no-store" => Some(NoStore),
|
||||
"no-transform" => Some(NoTransform),
|
||||
"only-if-cached" => Some(OnlyIfCached),
|
||||
"must-revalidate" => Some(MustRevalidate),
|
||||
"public" => Some(Public),
|
||||
"private" => Some(Private),
|
||||
"proxy-revalidate" => Some(ProxyRevalidate),
|
||||
"" => None,
|
||||
"no-cache" => Ok(NoCache),
|
||||
"no-store" => Ok(NoStore),
|
||||
"no-transform" => Ok(NoTransform),
|
||||
"only-if-cached" => Ok(OnlyIfCached),
|
||||
"must-revalidate" => Ok(MustRevalidate),
|
||||
"public" => Ok(Public),
|
||||
"private" => Ok(Private),
|
||||
"proxy-revalidate" => Ok(ProxyRevalidate),
|
||||
"" => Err(None),
|
||||
_ => match s.find('=') {
|
||||
Some(idx) if idx+1 < s.len() => match (&s[..idx], &s[idx+1..].trim_matches('"')) {
|
||||
("max-age" , secs) => secs.parse().map(MaxAge),
|
||||
("max-stale", secs) => secs.parse().map(MaxStale),
|
||||
("min-fresh", secs) => secs.parse().map(MinFresh),
|
||||
("s-maxage", secs) => secs.parse().map(SMaxAge),
|
||||
(left, right) => Some(Extension(left.to_string(), Some(right.to_string())))
|
||||
("max-age" , secs) => secs.parse().map(MaxAge).map_err(|x| Some(x)),
|
||||
("max-stale", secs) => secs.parse().map(MaxStale).map_err(|x| Some(x)),
|
||||
("min-fresh", secs) => secs.parse().map(MinFresh).map_err(|x| Some(x)),
|
||||
("s-maxage", secs) => secs.parse().map(SMaxAge).map_err(|x| Some(x)),
|
||||
(left, right) => Ok(Extension(left.to_string(), Some(right.to_string())))
|
||||
},
|
||||
Some(_) => None,
|
||||
None => Some(Extension(s.to_string(), None))
|
||||
Some(_) => Err(None),
|
||||
None => Ok(Extension(s.to_string(), None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,12 @@ pub enum ConnectionOption {
|
||||
}
|
||||
|
||||
impl FromStr for ConnectionOption {
|
||||
fn from_str(s: &str) -> Option<ConnectionOption> {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<ConnectionOption, ()> {
|
||||
match s {
|
||||
"keep-alive" => Some(KeepAlive),
|
||||
"close" => Some(Close),
|
||||
s => Some(ConnectionHeader(UniCase(s.to_string())))
|
||||
"keep-alive" => Ok(KeepAlive),
|
||||
"close" => Ok(Close),
|
||||
s => Ok(ConnectionHeader(UniCase(s.to_string())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ impl Header for Cookie {
|
||||
Ok(cookies_str) => {
|
||||
for cookie_str in cookies_str.split(';') {
|
||||
match cookie_str.trim().parse() {
|
||||
Some(cookie) => cookies.push(cookie),
|
||||
None => return None
|
||||
Ok(cookie) => cookies.push(cookie),
|
||||
Err(_) => return None
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -35,8 +35,9 @@ impl HeaderFormat for Date {
|
||||
}
|
||||
|
||||
impl FromStr for Date {
|
||||
fn from_str(s: &str) -> Option<Date> {
|
||||
tm_from_str(s).map(Date)
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Date, ()> {
|
||||
tm_from_str(s).map(Date).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ impl HeaderFormat for Expires {
|
||||
}
|
||||
|
||||
impl FromStr for Expires {
|
||||
fn from_str(s: &str) -> Option<Expires> {
|
||||
tm_from_str(s).map(Expires)
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Expires, ()> {
|
||||
tm_from_str(s).map(Expires).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Header for Host {
|
||||
};
|
||||
|
||||
let port = match idx {
|
||||
Some(idx) => s[idx + 1..].parse(),
|
||||
Some(idx) => s[idx + 1..].parse().ok(),
|
||||
None => None
|
||||
};
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ impl HeaderFormat for IfModifiedSince {
|
||||
}
|
||||
|
||||
impl FromStr for IfModifiedSince {
|
||||
fn from_str(s: &str) -> Option<IfModifiedSince> {
|
||||
tm_from_str(s).map(IfModifiedSince)
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<IfModifiedSince, ()> {
|
||||
tm_from_str(s).map(IfModifiedSince).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,9 @@ impl HeaderFormat for LastModified {
|
||||
}
|
||||
|
||||
impl FromStr for LastModified {
|
||||
fn from_str(s: &str) -> Option<LastModified> {
|
||||
tm_from_str(s).map(LastModified)
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<LastModified, ()> {
|
||||
tm_from_str(s).map(LastModified).ok_or(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ impl Header for SetCookie {
|
||||
match from_utf8(&set_cookies_raw[]) {
|
||||
Ok(s) if !s.is_empty() => {
|
||||
match s.parse() {
|
||||
Some(cookie) => set_cookies.push(cookie),
|
||||
None => ()
|
||||
Ok(cookie) => set_cookies.push(cookie),
|
||||
Err(_) => ()
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
||||
@@ -22,12 +22,13 @@ pub enum Protocol {
|
||||
}
|
||||
|
||||
impl FromStr for Protocol {
|
||||
fn from_str(s: &str) -> Option<Protocol> {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Protocol, ()> {
|
||||
if UniCase(s) == UniCase("websocket") {
|
||||
Some(WebSocket)
|
||||
Ok(WebSocket)
|
||||
}
|
||||
else {
|
||||
Some(ProtocolExt(s.to_string()))
|
||||
Ok(ProtocolExt(s.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user