refactor(headers): export all headers and utils directly under header

Currently headers are exported at many places. For example you can access
`Transfer-Encoding` header at `header`, `header::common` and
`header::common::transfer_encoding`. Per discussion on IRC with
@seanmonstar and @reem, all contents of headers will be exposed at `header`
directly. Parsing utilities will be exposed at `header::parsing`. Header
macros can now be used from other crates.

This breaks much code using headers. It should use everything it needs
directly from `header::`, encodings are exposed at `header::Encoding::`,
connection options are exposed at `header::ConnectionOption`.
This commit is contained in:
Pyfisch
2015-01-20 13:04:42 +01:00
parent 7a5813b4b2
commit 8d0e5bc302
37 changed files with 223 additions and 272 deletions

View File

@@ -1,26 +1,5 @@
//! Various functions, structs and enums useful for many headers.
pub use self::encoding::Encoding;
pub use self::encoding::Encoding::{
Chunked,
Gzip,
Deflate,
Compress,
Identity,
EncodingExt};
pub use self::quality_item::{QualityItem, qitem};
pub use self::quality_item::QualityItem;
pub use self::quality_item::qitem;
pub use self::time::tm_from_str;
pub use self::util::{
from_one_raw_str,
from_comma_delimited,
from_one_comma_delimited,
fmt_comma_delimited};
pub mod encoding;
pub mod quality_item;
pub mod time;
pub mod util;
mod encoding;
mod quality_item;

View File

@@ -1,52 +0,0 @@
//! Utility functions for Header implementations.
use std::str;
use std::fmt;
/// Reads a single raw string when parsing a header
pub fn from_one_raw_str<T: str::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 str::from_utf8(&raw[0][]) {
Ok(s) => str::FromStr::from_str(s),
Err(_) => None
}
}
/// Reads a comma-delimited raw header into a Vec.
#[inline]
pub fn from_comma_delimited<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<Vec<T>> {
if raw.len() != 1 {
return None;
}
// we JUST checked that raw.len() == 1, so raw[0] WILL exist.
from_one_comma_delimited(&raw[0][])
}
/// Reads a comma-delimited raw string into a Vec.
pub fn from_one_comma_delimited<T: str::FromStr>(raw: &[u8]) -> Option<Vec<T>> {
match str::from_utf8(raw) {
Ok(s) => {
Some(s.as_slice()
.split(',')
.map(|x| x.trim())
.filter_map(str::FromStr::from_str)
.collect())
}
Err(_) => None
}
}
/// Format an array into a comma-delimited string.
pub fn fmt_comma_delimited<T: fmt::String>(fmt: &mut fmt::Formatter, parts: &[T]) -> fmt::Result {
let last = parts.len() - 1;
for (i, part) in parts.iter().enumerate() {
try!(write!(fmt, "{}", part));
if i < last {
try!(write!(fmt, ", "));
}
}
Ok(())
}