Skip to content

Commit c9f2c84

Browse files
committed
fix(rustup): get rid of slice pattern, add Reflect bounds
* remove slice pattern * add `Reflect` trait bounds where necessary
1 parent 8e1cd5e commit c9f2c84

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/header/common/authorization.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::fmt;
22
use std::str::{FromStr, from_utf8};
33
use std::ops::{Deref, DerefMut};
4+
use std::marker::Reflect;
45
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
56
use header::{Header, HeaderFormat};
67

@@ -22,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
2223
}
2324
}
2425

25-
impl<S: Scheme + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
26+
impl<S: Scheme + Reflect + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
2627
fn header_name() -> &'static str {
2728
"Authorization"
2829
}
@@ -43,7 +44,7 @@ impl<S: Scheme + 'static> Header for Authorization<S> where <S as FromStr>::Err:
4344
}
4445
}
4546

46-
impl<S: Scheme + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
47+
impl<S: Scheme + Reflect + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
4748
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
4849
match Scheme::scheme(None::<S>) {
4950
Some(scheme) => try!(write!(fmt, "{} ", scheme)),

src/net.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::mem;
77
use std::path::Path;
88
use std::raw::{self, TraitObject};
99
use std::sync::Arc;
10+
use std::marker::Reflect;
1011

1112
use openssl::ssl::{Ssl, SslStream, SslContext};
1213
use openssl::ssl::SslVerifyMode::SslVerifyNone;
@@ -117,13 +118,13 @@ impl NetworkStream + Send {
117118
impl NetworkStream + Send {
118119
/// Is the underlying type in this trait object a T?
119120
#[inline]
120-
pub fn is<T: 'static>(&self) -> bool {
121+
pub fn is<T: Reflect + 'static>(&self) -> bool {
121122
self.get_type_id() == TypeId::of::<T>()
122123
}
123124

124125
/// If the underlying type is T, get a reference to the contained data.
125126
#[inline]
126-
pub fn downcast_ref<T: 'static>(&self) -> Option<&T> {
127+
pub fn downcast_ref<T: Reflect + 'static>(&self) -> Option<&T> {
127128
if self.is::<T>() {
128129
Some(unsafe { self.downcast_ref_unchecked() })
129130
} else {
@@ -134,7 +135,7 @@ impl NetworkStream + Send {
134135
/// If the underlying type is T, get a mutable reference to the contained
135136
/// data.
136137
#[inline]
137-
pub fn downcast_mut<T: 'static>(&mut self) -> Option<&mut T> {
138+
pub fn downcast_mut<T: Reflect + 'static>(&mut self) -> Option<&mut T> {
138139
if self.is::<T>() {
139140
Some(unsafe { self.downcast_mut_unchecked() })
140141
} else {
@@ -143,7 +144,7 @@ impl NetworkStream + Send {
143144
}
144145

145146
/// If the underlying type is T, extract it.
146-
pub fn downcast<T: 'static>(self: Box<NetworkStream + Send>)
147+
pub fn downcast<T: Reflect + 'static>(self: Box<NetworkStream + Send>)
147148
-> Result<Box<T>, Box<NetworkStream + Send>> {
148149
if self.is::<T>() {
149150
Ok(unsafe { self.downcast_unchecked() })

src/uri.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ impl FromStr for RequestUri {
5353
type Err = HttpError;
5454

5555
fn from_str(s: &str) -> Result<RequestUri, HttpError> {
56-
match s.as_bytes() {
57-
[] => Err(HttpError::HttpUriError(UrlError::InvalidCharacter)),
58-
[b'*'] => Ok(RequestUri::Star),
59-
[b'/', ..] => Ok(RequestUri::AbsolutePath(s.to_string())),
60-
bytes if bytes.contains(&b'/') => {
61-
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
62-
}
63-
_ => {
64-
let mut temp = "http://".to_string();
65-
temp.push_str(s);
66-
try!(Url::parse(&temp[..]));
67-
todo!("compare vs u.authority()");
68-
Ok(RequestUri::Authority(s.to_string()))
69-
}
70-
56+
let bytes = s.as_bytes();
57+
if bytes == [] {
58+
Err(HttpError::HttpUriError(UrlError::InvalidCharacter))
59+
} else if bytes == b"*" {
60+
Ok(RequestUri::Star)
61+
} else if bytes.starts_with(b"/") {
62+
Ok(RequestUri::AbsolutePath(s.to_string()))
63+
} else if bytes.contains(&b'/') {
64+
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
65+
} else {
66+
let mut temp = "http://".to_string();
67+
temp.push_str(s);
68+
try!(Url::parse(&temp[..]));
69+
todo!("compare vs u.authority()");
70+
Ok(RequestUri::Authority(s.to_string()))
7171
}
7272
}
7373
}

0 commit comments

Comments
 (0)