multiaddr: future-proof error type (#506)

This commit is contained in:
Toralf Wittner 2018-09-21 10:39:36 +02:00 committed by GitHub
parent 3f3d81cc95
commit b61d9faece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -15,7 +15,9 @@ pub enum Error {
InvalidUvar(decode::Error),
ParsingError(Box<dyn error::Error + Send + Sync>),
UnknownProtocolId(u32),
UnknownProtocolString
UnknownProtocolString,
#[doc(hidden)]
__Nonexhaustive
}
impl fmt::Display for Error {
@ -27,7 +29,8 @@ impl fmt::Display for Error {
Error::InvalidUvar(e) => write!(f, "failed to decode unsigned varint: {}", e),
Error::ParsingError(e) => write!(f, "failed to parse: {}", e),
Error::UnknownProtocolId(id) => write!(f, "unknown protocol id: {}", id),
Error::UnknownProtocolString => f.write_str("unknown protocol string")
Error::UnknownProtocolString => f.write_str("unknown protocol string"),
Error::__Nonexhaustive => f.write_str("__Nonexhaustive")
}
}
}

View File

@ -5,7 +5,7 @@ use std::{
borrow::Cow,
convert::From,
fmt,
io::{self, Cursor, Write},
io::{Cursor, Write},
net::{Ipv4Addr, Ipv6Addr},
str::{self, FromStr}
};
@ -232,7 +232,7 @@ impl<'a> Protocol<'a> {
/// Encode this protocol by writing its binary representation into
/// the given `Write` impl.
pub fn write_bytes<W: Write>(&self, w: &mut W) -> io::Result<()> {
pub fn write_bytes<W: Write>(&self, w: &mut W) -> Result<()> {
let mut buf = encode::u32_buffer();
match self {
Protocol::Ip4(addr) => {