Skip to content

Commit

Permalink
Merge pull request rust-bitcoin#85 from alekseysidorov/hotfix-network…
Browse files Browse the repository at this point in the history
…-from-str-err

Hotfix: replace serde error with the io error.
  • Loading branch information
tamasblummer authored May 24, 2018
2 parents 6b1872e + cf4024b commit ee65534
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ macro_rules! user_enum {
}

impl ::std::str::FromStr for $name {
type Err = ::serde::de::value::Error;
type Err = ::std::io::Error;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
$($txt => Ok($name::$elem)),*,
_ => Err(::serde::de::Error::syntax(stringify!(s)))
_ => Err(::std::io::Error::new(
::std::io::ErrorKind::InvalidInput,
format!("Unknown network (type {})", s),
)),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/network/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod tests {
assert_eq!(Network::Bitcoin.to_string(), "bitcoin");
assert_eq!(Network::Testnet.to_string(), "testnet");

assert_eq!("bitcoin".parse(), Ok(Network::Bitcoin));
assert_eq!("testnet".parse(), Ok(Network::Testnet));
assert_eq!("bitcoin".parse::<Network>().unwrap(), Network::Bitcoin);
assert_eq!("testnet".parse::<Network>().unwrap(), Network::Testnet);
assert!("fakenet".parse::<Network>().is_err());
}
}
Expand Down

0 comments on commit ee65534

Please sign in to comment.