Exposed the 'from_one_raw_str' function for use in defining new header structs.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
use std::from_str::FromStr;
|
use std::from_str::FromStr;
|
||||||
|
|
||||||
/// The `Connection` header.
|
/// The `Connection` header.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
|
|
||||||
use header::Header;
|
use header::Header;
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
|
|
||||||
/// The `Content-Length` header.
|
/// The `Content-Length` header.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
use mime::Mime;
|
use mime::Mime;
|
||||||
|
|
||||||
/// The `Content-Type` header.
|
/// The `Content-Type` header.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
use std::from_str::FromStr;
|
use std::from_str::FromStr;
|
||||||
use time::{Tm, strptime};
|
use time::{Tm, strptime};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
|
|
||||||
/// The `Host` header.
|
/// The `Host` header.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
|
|
||||||
/// The `Location` header.
|
/// The `Location` header.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ pub use self::server::Server;
|
|||||||
pub use self::date::Date;
|
pub use self::date::Date;
|
||||||
pub use self::location::Location;
|
pub use self::location::Location;
|
||||||
|
|
||||||
use std::from_str::FromStr;
|
|
||||||
use std::str::from_utf8;
|
|
||||||
|
|
||||||
/// Exposes the Host header.
|
/// Exposes the Host header.
|
||||||
pub mod host;
|
pub mod host;
|
||||||
|
|
||||||
@@ -50,14 +47,6 @@ pub mod date;
|
|||||||
/// Exposes the Location header.
|
/// Exposes the Location header.
|
||||||
pub mod location;
|
pub mod location;
|
||||||
|
|
||||||
fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
|
pub mod util;
|
||||||
if raw.len() != 1 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
|
|
||||||
match from_utf8(unsafe { raw.as_slice().unsafe_get(0).as_slice() }) {
|
|
||||||
Some(s) => FromStr::from_str(s),
|
|
||||||
None => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
|
|
||||||
/// The `Server` header field.
|
/// The `Server` header field.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use header::Header;
|
use header::Header;
|
||||||
use std::fmt::{mod, Show};
|
use std::fmt::{mod, Show};
|
||||||
use super::from_one_raw_str;
|
use super::util::from_one_raw_str;
|
||||||
|
|
||||||
/// The `User-Agent` header field.
|
/// The `User-Agent` header field.
|
||||||
///
|
///
|
||||||
|
|||||||
16
src/header/common/util.rs
Normal file
16
src/header/common/util.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//! Utility functions for Header implementations.
|
||||||
|
|
||||||
|
use std::from_str::FromStr;
|
||||||
|
use std::str::from_utf8;
|
||||||
|
|
||||||
|
/// Utility function that reads a single raw string when parsing a header
|
||||||
|
pub fn from_one_raw_str<T: FromStr>(raw: &[Vec<u8>]) -> Option<T> {
|
||||||
|
if raw.len() != 1 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
|
||||||
|
match from_utf8(unsafe { raw.as_slice().unsafe_get(0).as_slice() }) {
|
||||||
|
Some(s) => FromStr::from_str(s),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user