refactor(headers): errors for parse_header

Header::parse_header() returns now a hyper Result instead of an option
this will enable more precise Error messages in the future, currently
most failures are reported as ::Error::Header.

BREAKING CHANGE: parse_header returns Result instead of Option, related
code did also change
This commit is contained in:
Pyfisch
2015-06-06 22:04:01 +02:00
parent 763746153e
commit 195a89fa91
19 changed files with 140 additions and 132 deletions

View File

@@ -60,11 +60,11 @@ impl Item {
Some(val) => Some(val),
None => {
match parse::<H>(self.raw.as_ref().expect("item.raw must exist")) {
Some(typed) => {
Ok(typed) => {
unsafe { self.typed.insert(tid, typed); }
self.typed.get(tid)
},
None => None
Err(_) => None
}
}
}.map(|typed| unsafe { typed.downcast_ref_unchecked() })
@@ -74,10 +74,10 @@ impl Item {
let tid = TypeId::of::<H>();
if self.typed.get_mut(tid).is_none() {
match parse::<H>(self.raw.as_ref().expect("item.raw must exist")) {
Some(typed) => {
Ok(typed) => {
unsafe { self.typed.insert(tid, typed); }
},
None => ()
Err(_) => ()
}
}
self.typed.get_mut(tid).map(|typed| unsafe { typed.downcast_mut_unchecked() })
@@ -85,7 +85,7 @@ impl Item {
}
#[inline]
fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> Option<Box<HeaderFormat + Send + Sync>> {
fn parse<H: Header + HeaderFormat>(raw: &Vec<Vec<u8>>) -> ::Result<Box<HeaderFormat + Send + Sync>> {
Header::parse_header(&raw[..]).map(|h: H| {
// FIXME: Use Type ascription
let h: Box<HeaderFormat + Send + Sync> = Box::new(h);