Update to new FromStr

This commit is contained in:
Matthew Maurer 2015-02-02 19:38:52 -05:00
parent 90f5567c2d
commit 6ac0b19130
2 changed files with 10 additions and 8 deletions

View File

@ -533,10 +533,10 @@ impl DbError {
detail: map.remove(&b'D'),
hint: map.remove(&b'H'),
position: match map.remove(&b'P') {
Some(pos) => Some(ErrorPosition::Normal(try!(pos.parse().ok_or(())))),
Some(pos) => Some(ErrorPosition::Normal(try!(pos.parse().ok().ok_or(())))),
None => match map.remove(&b'p') {
Some(pos) => Some(ErrorPosition::Internal {
position: try!(pos.parse().ok_or(())),
position: try!(pos.parse().ok().ok_or(())),
query: try!(map.remove(&b'q').ok_or(()))
}),
None => None
@ -549,7 +549,7 @@ impl DbError {
datatype: map.remove(&b'd'),
constraint: map.remove(&b'n'),
file: try!(map.remove(&b'F').ok_or(())),
line: try!(map.remove(&b'L').and_then(|l| l.parse()).ok_or(())),
line: try!(map.remove(&b'L').and_then(|l| l.parse().ok()).ok_or(())),
routine: try!(map.remove(&b'R').ok_or(())),
})
}

View File

@ -371,7 +371,7 @@ fn get_authority(rawurl: &str) ->
// If we have a port string, ensure it parses to u16.
let port = match port {
None => None,
opt => match opt.and_then(|p| FromStr::from_str(p)) {
opt => match opt.and_then(|p| FromStr::from_str(p).ok()) {
None => return Err(format!("Failed to parse port: {:?}", port)),
opt => opt
}
@ -428,14 +428,16 @@ fn get_query_fragment(rawurl: &str) -> DecodeResult<(Query, Option<String>)> {
}
impl FromStr for Url {
fn from_str(s: &str) -> Option<Url> {
Url::parse(s).ok()
type Err = String;
fn from_str(s: &str) -> Result<Url, String> {
Url::parse(s)
}
}
impl FromStr for Path {
fn from_str(s: &str) -> Option<Path> {
Path::parse(s).ok()
type Err = String;
fn from_str(s: &str) -> Result<Path, String> {
Path::parse(s)
}
}