Remove get and rename get_ref to get

Since `get_ref` (now `get`) takes `&self` there is no need
for a special cloning method.
This commit is contained in:
Jonathan Reem
2014-09-20 04:18:25 -07:00
parent 91cc29e0aa
commit 858a09304a
5 changed files with 8 additions and 22 deletions

View File

@@ -111,7 +111,7 @@ impl Request<Fresh> {
let mut chunked = true; let mut chunked = true;
let mut len = 0; let mut len = 0;
match self.headers.get_ref::<common::ContentLength>() { match self.headers.get::<common::ContentLength>() {
Some(cl) => { Some(cl) => {
chunked = false; chunked = false;
len = cl.len(); len = cl.len();
@@ -122,7 +122,7 @@ impl Request<Fresh> {
// cant do in match above, thanks borrowck // cant do in match above, thanks borrowck
if chunked { if chunked {
//TODO: use CollectionViews (when implemented) to prevent double hash/lookup //TODO: use CollectionViews (when implemented) to prevent double hash/lookup
let encodings = match self.headers.get::<common::TransferEncoding>() { let encodings = match self.headers.get::<common::TransferEncoding>().map(|h| h.clone()) {
Some(common::TransferEncoding(mut encodings)) => { Some(common::TransferEncoding(mut encodings)) => {
//TODO: check if chunked is already in encodings. use HashSet? //TODO: check if chunked is already in encodings. use HashSet?
encodings.push(common::transfer_encoding::Chunked); encodings.push(common::transfer_encoding::Chunked);

View File

@@ -33,7 +33,7 @@ impl Response {
debug!("{}", headers); debug!("{}", headers);
let body = if headers.has::<TransferEncoding>() { let body = if headers.has::<TransferEncoding>() {
match headers.get_ref::<TransferEncoding>() { match headers.get::<TransferEncoding>() {
Some(&TransferEncoding(ref codings)) => { Some(&TransferEncoding(ref codings)) => {
if codings.len() > 1 { if codings.len() > 1 {
debug!("TODO: #2 handle other codings: {}", codings); debug!("TODO: #2 handle other codings: {}", codings);
@@ -49,7 +49,7 @@ impl Response {
None => unreachable!() None => unreachable!()
} }
} else if headers.has::<ContentLength>() { } else if headers.has::<ContentLength>() {
match headers.get_ref::<ContentLength>() { match headers.get::<ContentLength>() {
Some(&ContentLength(len)) => SizedReader(stream, len), Some(&ContentLength(len)) => SizedReader(stream, len),
None => unreachable!() None => unreachable!()
} }

View File

@@ -118,20 +118,6 @@ impl Headers {
self.data.insert(CaseInsensitive(Slice(header_name::<H>())), RWLock::new(Typed(box value as Box<Header + Send + Sync>))); self.data.insert(CaseInsensitive(Slice(header_name::<H>())), RWLock::new(Typed(box value as Box<Header + Send + Sync>)));
} }
/// Get a clone of the header field's value, if it exists.
///
/// Example:
///
/// ```
/// # use hyper::header::Headers;
/// # use hyper::header::common::ContentType;
/// # let mut headers = Headers::new();
/// let content_type = headers.get::<ContentType>();
/// ```
pub fn get<H: Header + Clone>(&self) -> Option<H> {
self.get_ref().map(|v: &H| v.clone())
}
/// Access the raw value of a header, if it exists and has not /// Access the raw value of a header, if it exists and has not
/// been already parsed. /// been already parsed.
/// ///
@@ -158,7 +144,7 @@ impl Headers {
} }
/// Get a reference to the header field's value, if it exists. /// Get a reference to the header field's value, if it exists.
pub fn get_ref<H: Header>(&self) -> Option<&H> { pub fn get<H: Header>(&self) -> Option<&H> {
self.data.find(&CaseInsensitive(Slice(header_name::<H>()))).and_then(|item| { self.data.find(&CaseInsensitive(Slice(header_name::<H>()))).and_then(|item| {
let done = match *item.read() { let done = match *item.read() {
// Huge borrowck hack here, should be refactored to just return here. // Huge borrowck hack here, should be refactored to just return here.

View File

@@ -46,7 +46,7 @@ impl Request {
let body = if headers.has::<ContentLength>() { let body = if headers.has::<ContentLength>() {
match headers.get_ref::<ContentLength>() { match headers.get::<ContentLength>() {
Some(&ContentLength(len)) => SizedReader(stream, len), Some(&ContentLength(len)) => SizedReader(stream, len),
None => unreachable!() None => unreachable!()
} }

View File

@@ -72,7 +72,7 @@ impl Response<Fresh> {
let mut chunked = true; let mut chunked = true;
let mut len = 0; let mut len = 0;
match self.headers.get_ref::<common::ContentLength>() { match self.headers.get::<common::ContentLength>() {
Some(cl) => { Some(cl) => {
chunked = false; chunked = false;
len = cl.len(); len = cl.len();
@@ -83,7 +83,7 @@ impl Response<Fresh> {
// cant do in match above, thanks borrowck // cant do in match above, thanks borrowck
if chunked { if chunked {
//TODO: use CollectionViews (when implemented) to prevent double hash/lookup //TODO: use CollectionViews (when implemented) to prevent double hash/lookup
let encodings = match self.headers.get::<common::TransferEncoding>() { let encodings = match self.headers.get::<common::TransferEncoding>().map(|h| h.clone()) {
Some(common::TransferEncoding(mut encodings)) => { Some(common::TransferEncoding(mut encodings)) => {
//TODO: check if chunked is already in encodings. use HashSet? //TODO: check if chunked is already in encodings. use HashSet?
encodings.push(common::transfer_encoding::Chunked); encodings.push(common::transfer_encoding::Chunked);