Skip to content

Commit

Permalink
fix(*): FromStr now returns a Result, not an Option.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonTeixidor committed Feb 4, 2015
1 parent 91957fb commit ce33ef2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(collections, core, io)]
#![feature(core, io)]

extern crate "rustc-serialize" as rustc_serialize;
extern crate nickel;
Expand Down
7 changes: 4 additions & 3 deletions src/mimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ macro_rules! mimes {
}

impl FromStr for MediaType {
fn from_str(s: &str) -> Option<MediaType> {
type Err = &'static str;
fn from_str(s: &str) -> Result<MediaType, &'static str> {
match s {
$(
$(
$as_s => Some(MediaType::$name)
$as_s => Ok(MediaType::$name)
),*
),*,
_ => None
_ => Err("Not a valid MediaType.")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'a, 'b> Response<'a, 'b> {
self.origin.headers.content_length = None;

self.origin.headers.content_type = path.extension_str()
.and_then(|s| s.parse())
.and_then(|s| s.parse().ok())
.map(mimes::get_media_type);
self.origin.headers.server = Some(String::from_str("Nickel"));
copy(&mut file, self.origin)
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a, 'b> Response<'a, 'b> {
#[test]
fn matches_content_type () {
let path = &Path::new("test.txt");
let content_type = path.extension_str().and_then(|s| s.parse());
let content_type = path.extension_str().and_then(|s| s.parse().ok());

assert_eq!(content_type, Some(mimes::MediaType::Txt));
let content_type = content_type.map(mimes::get_media_type).unwrap();
Expand Down

0 comments on commit ce33ef2

Please sign in to comment.