Skip to content

Commit 09c847a

Browse files
seanmonstarmikedilger
authored andcommitted
chore(stability): remove core feature gate
1 parent 9951c7a commit 09c847a

File tree

10 files changed

+191
-266
lines changed

10 files changed

+191
-266
lines changed

src/client/response.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Client Responses
22
use std::io::{self, Read};
3-
use std::num::FromPrimitive;
43
use std::marker::PhantomData;
54

65
use buffer::BufReader;
@@ -13,7 +12,6 @@ use http::HttpReader::{SizedReader, ChunkedReader, EofReader};
1312
use status;
1413
use version;
1514
use HttpResult;
16-
use HttpError::HttpStatusError;
1715

1816
/// A response for a client request to a remote server.
1917
pub struct Response<S = HttpStream> {
@@ -39,10 +37,7 @@ impl Response {
3937
let raw_status = head.subject;
4038
let headers = head.headers;
4139

42-
let status = match FromPrimitive::from_u16(raw_status.0) {
43-
Some(status) => status,
44-
None => return Err(HttpStatusError)
45-
};
40+
let status = status::StatusCode::from_u16(raw_status.0);
4641
debug!("version={:?}, status={:?}", head.version, status);
4742
debug!("headers={:?}", headers);
4843

src/header/common/authorization.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use std::any::Any;
12
use std::fmt;
23
use std::str::{FromStr, from_utf8};
34
use std::ops::{Deref, DerefMut};
4-
use std::marker::Reflect;
55
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
66
use header::{Header, HeaderFormat};
77

@@ -23,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
2323
}
2424
}
2525

26-
impl<S: Scheme + Reflect + 'static> Header for Authorization<S> where <S as FromStr>::Err: 'static {
26+
impl<S: Scheme + Any> Header for Authorization<S> where <S as FromStr>::Err: 'static {
2727
fn header_name() -> &'static str {
2828
"Authorization"
2929
}
@@ -44,7 +44,7 @@ impl<S: Scheme + Reflect + 'static> Header for Authorization<S> where <S as From
4444
}
4545
}
4646

47-
impl<S: Scheme + Reflect + 'static> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
47+
impl<S: Scheme + Any> HeaderFormat for Authorization<S> where <S as FromStr>::Err: 'static {
4848
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
4949
match Scheme::scheme(None::<S>) {
5050
Some(scheme) => try!(write!(fmt, "{} ", scheme)),
@@ -71,7 +71,7 @@ impl Scheme for String {
7171
}
7272

7373
fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
74-
write!(f, "{}", self)
74+
write!(f, "{}", self)
7575
}
7676
}
7777

src/header/internals/item.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
use std::any::Any;
12
use std::any::TypeId;
23
use std::fmt;
34
use std::str::from_utf8;
45

6+
use typeable::Typeable;
7+
58
use super::cell::{OptCell, PtrMapCell};
69
use header::{Header, HeaderFormat};
710

@@ -24,7 +27,7 @@ impl Item {
2427
#[inline]
2528
pub fn new_typed(ty: Box<HeaderFormat + Send + Sync>) -> Item {
2629
let map = PtrMapCell::new();
27-
unsafe { map.insert((&*ty).get_type_id(), ty); }
30+
unsafe { map.insert((*ty).get_type(), ty); }
2831
Item {
2932
raw: OptCell::new(None),
3033
typed: map,
@@ -51,7 +54,7 @@ impl Item {
5154
&raw[..]
5255
}
5356

54-
pub fn typed<H: Header + HeaderFormat>(&self) -> Option<&H> {
57+
pub fn typed<H: Header + HeaderFormat + Any>(&self) -> Option<&H> {
5558
let tid = TypeId::of::<H>();
5659
match self.typed.get(tid) {
5760
Some(val) => Some(val),

src/header/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::iter::{FromIterator, IntoIterator};
1212
use std::{mem, fmt};
1313

1414
use {httparse, traitobject};
15+
use typeable::Typeable;
1516
use unicase::UniCase;
1617

1718
use self::internals::Item;
@@ -50,7 +51,7 @@ pub trait Header: Clone + Any + Send + Sync {
5051
/// A trait for any object that will represent a header field and value.
5152
///
5253
/// This trait represents the formatting of a Header for output to a TcpStream.
53-
pub trait HeaderFormat: fmt::Debug + HeaderClone + Any + Send + Sync {
54+
pub trait HeaderFormat: fmt::Debug + HeaderClone + Any + Typeable + Send + Sync {
5455
/// Format a header to be output into a TcpStream.
5556
///
5657
/// This method is not allowed to introduce an Err not produced
@@ -61,12 +62,12 @@ pub trait HeaderFormat: fmt::Debug + HeaderClone + Any + Send + Sync {
6162

6263
#[doc(hidden)]
6364
pub trait HeaderClone {
64-
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send>;
65+
fn clone_box(&self) -> Box<HeaderFormat + Send + Sync>;
6566
}
6667

67-
impl<T: HeaderFormat + Send + Sync + Clone> HeaderClone for T {
68+
impl<T: HeaderFormat + Clone> HeaderClone for T {
6869
#[inline]
69-
fn clone_box(&self) -> Box<HeaderFormat + Sync + Send> {
70+
fn clone_box(&self) -> Box<HeaderFormat + Send + Sync> {
7071
Box::new(self.clone())
7172
}
7273
}

src/header/shared/quality_item.rs

Lines changed: 36 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use std::cmp;
77
use std::default::Default;
88
use std::fmt;
9-
use std::num::{FromPrimitive, ToPrimitive};
109
use std::str;
1110

1211
/// Represents a quality used in quality values.
@@ -20,7 +19,7 @@ use std::str;
2019
/// floating point data type (`f32`) consumes four bytes, hyper uses an `u16` value to store the
2120
/// quality internally. For performance reasons you may set quality directly to a value between
2221
/// 0 and 1000 e.g. `Quality(532)` matches the quality `q=0.532`.
23-
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
22+
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
2423
pub struct Quality(pub u16);
2524

2625
impl fmt::Display for Quality {
@@ -33,43 +32,6 @@ impl fmt::Display for Quality {
3332
}
3433
}
3534

36-
impl FromPrimitive for Quality {
37-
fn from_i64(n: i64) -> Option<Quality> {
38-
match n >= 0 {
39-
true => FromPrimitive::from_u64(n as u64),
40-
false => None,
41-
}
42-
}
43-
44-
fn from_u64(n: u64) -> Option<Quality> {
45-
match n <= 1000 {
46-
true => Some(Quality(n as u16)),
47-
false => None,
48-
}
49-
}
50-
51-
fn from_f64(n: f64) -> Option<Quality> {
52-
match n >= 0f64 && n <= 1f64 {
53-
true => Some(Quality((n * 1000f64) as u16)),
54-
false => None,
55-
}
56-
}
57-
}
58-
59-
impl ToPrimitive for Quality {
60-
fn to_i64(&self) -> Option<i64> {
61-
Some(self.0 as i64)
62-
}
63-
64-
fn to_u64(&self) -> Option<u64> {
65-
Some(self.0 as u64)
66-
}
67-
68-
fn to_f64(&self) -> Option<f64> {
69-
Some((self.0 as f64) / 1000f64)
70-
}
71-
}
72-
7335
impl Default for Quality {
7436
fn default() -> Quality {
7537
Quality(1000)
@@ -91,7 +53,10 @@ impl<T> QualityItem<T> {
9153
/// The item can be of any type.
9254
/// The quality should be a value in the range [0, 1].
9355
pub fn new(item: T, quality: Quality) -> QualityItem<T> {
94-
QualityItem{item: item, quality: quality}
56+
QualityItem {
57+
item: item,
58+
quality: quality
59+
}
9560
}
9661
}
9762

@@ -136,12 +101,21 @@ impl<T: str::FromStr> str::FromStr for QualityItem<T> {
136101
}
137102
}
138103
match raw_item.parse::<T>() {
139-
Ok(item) => Ok(QualityItem::new(item, FromPrimitive::from_f32(quality).unwrap())),
104+
// we already checked above that the quality is within range
105+
Ok(item) => Ok(QualityItem::new(item, from_f32(quality))),
140106
Err(_) => return Err(()),
141107
}
142108
}
143109
}
144110

111+
fn from_f32(f: f32) -> Quality {
112+
// this function is only used internally. A check that `f` is within range
113+
// should be done before calling this method. Just in case, this
114+
// debug_assert should catch if we were forgetful
115+
debug_assert!(f >= 0f32 && f <= 1f32, "q value must be between 0.0 and 1.0");
116+
Quality((f * 1000f32) as u16)
117+
}
118+
145119
/// Convinience function to wrap a value in a `QualityItem`
146120
/// Sets `q` to the default 1.0
147121
pub fn qitem<T>(item: T) -> QualityItem<T> {
@@ -150,13 +124,12 @@ pub fn qitem<T>(item: T) -> QualityItem<T> {
150124

151125
/// Convenience function to create a `Quality` fromt a float.
152126
pub fn q(f: f32) -> Quality {
153-
FromPrimitive::from_f32(f).expect("q value must be between 0.0 and 1.0")
127+
assert!(f >= 0f32 && f <= 1f32, "q value must be between 0.0 and 1.0");
128+
from_f32(f)
154129
}
155130

156131
#[cfg(test)]
157132
mod tests {
158-
use std::num::FromPrimitive;
159-
160133
use super::*;
161134
use super::super::encoding::*;
162135

@@ -206,25 +179,32 @@ mod tests {
206179
assert_eq!(x, Err(()));
207180
}
208181
#[test]
182+
fn test_quality_item_from_str6() {
183+
let x: Result<QualityItem<Encoding>, ()> = "gzip; q=2".parse();
184+
assert_eq!(x, Err(()));
185+
}
186+
#[test]
209187
fn test_quality_item_ordering() {
210188
let x: QualityItem<Encoding> = "gzip; q=0.5".parse().ok().unwrap();
211189
let y: QualityItem<Encoding> = "gzip; q=0.273".parse().ok().unwrap();
212190
let comparision_result: bool = x.gt(&y);
213191
assert_eq!(comparision_result, true)
214192
}
193+
215194
#[test]
216195
fn test_quality() {
217-
assert_eq!(Some(Quality(421)), FromPrimitive::from_f64(0.421f64));
218-
assert_eq!(Some(Quality(421)), FromPrimitive::from_f32(0.421f32));
219-
assert_eq!(Some(Quality(421)), FromPrimitive::from_i16(421i16));
220-
assert_eq!(Some(Quality(421)), FromPrimitive::from_i32(421i32));
221-
assert_eq!(Some(Quality(421)), FromPrimitive::from_i64(421i64));
222-
assert_eq!(Some(Quality(421)), FromPrimitive::from_u16(421u16));
223-
assert_eq!(Some(Quality(421)), FromPrimitive::from_u32(421u32));
224-
assert_eq!(Some(Quality(421)), FromPrimitive::from_u64(421u64));
225-
226-
assert_eq!(None::<Quality>, FromPrimitive::from_i16(-5i16));
227-
assert_eq!(None::<Quality>, FromPrimitive::from_i32(5000i32));
228-
assert_eq!(None::<Quality>, FromPrimitive::from_f32(2.5f32));
196+
assert_eq!(q(0.5), Quality(500));
197+
}
198+
199+
#[test]
200+
#[should_panic]
201+
fn test_quality_invalid() {
202+
q(-1.0);
203+
}
204+
205+
#[test]
206+
#[should_panic]
207+
fn test_quality_invalid2() {
208+
q(2.0);
229209
}
230210
}

src/http.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use std::borrow::{Cow, ToOwned};
33
use std::cmp::min;
44
use std::io::{self, Read, Write, BufRead};
5-
use std::num::FromPrimitive;
65

76
use httparse;
87

@@ -378,11 +377,8 @@ impl<'a> TryParse for httparse::Response<'a> {
378377
Ok(match try!(res.parse(buf)) {
379378
httparse::Status::Complete(len) => {
380379
let code = res.code.unwrap();
381-
let reason = match <StatusCode as FromPrimitive>::from_u16(code) {
382-
Some(status) => match status.canonical_reason() {
383-
Some(reason) => Cow::Borrowed(reason),
384-
None => Cow::Owned(res.reason.unwrap().to_owned())
385-
},
380+
let reason = match StatusCode::from_u16(code).canonical_reason() {
381+
Some(reason) => Cow::Borrowed(reason),
386382
None => Cow::Owned(res.reason.unwrap().to_owned())
387383
};
388384
httparse::Status::Complete((Incoming {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")]
2-
#![feature(core)]
32
#![deny(missing_docs)]
43
#![cfg_attr(test, deny(warnings))]
54
#![cfg_attr(test, feature(test))]

src/net.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::net::{SocketAddr, ToSocketAddrs, TcpStream, TcpListener};
66
use std::mem;
77
use std::path::Path;
88
use std::sync::Arc;
9-
use std::marker::Reflect;
109

1110
use openssl::ssl::{Ssl, SslStream, SslContext};
1211
use openssl::ssl::SslVerifyMode::SslVerifyNone;
@@ -135,7 +134,7 @@ impl NetworkStream + Send {
135134
/// If the underlying type is T, get a mutable reference to the contained
136135
/// data.
137136
#[inline]
138-
pub fn downcast_mut<T: Reflect + 'static>(&mut self) -> Option<&mut T> {
137+
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
139138
if self.is::<T>() {
140139
Some(unsafe { self.downcast_mut_unchecked() })
141140
} else {
@@ -144,7 +143,7 @@ impl NetworkStream + Send {
144143
}
145144

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

0 commit comments

Comments
 (0)