Skip to content

Commit 8636c44

Browse files
author
rstade
committed
impl some From traits for ErrorKind
1 parent a615434 commit 8636c44

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

framework/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ rust-sctp = { git="https://github.com/netsys/rust-sctp", optional = true}
2727
toml = "~0.4"
2828
# Hack for SHM
2929
uuid= { version = ">=0.7", features=["v4"] }
30-
#error-chain = ">=0.12"
3130
tokio-core=">=0.1.8"
3231
futures=">=0.1.14"
3332
eui48 = { version= ">=0.3" }
3433
separator = ">= 0.3"
3534
serde_derive = "1.0"
3635
serde = "1.0"
36+
ipnet = ">=1.0"
3737

3838
[features]
3939
default = []

framework/src/common/errors.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
use std::fmt::{ Display, Formatter};
2+
use std::net::AddrParseError;
3+
use std::string::String;
4+
use ipnet;
5+
6+
27
/*
38
error_chain! {
49
errors {
@@ -119,26 +124,52 @@ pub enum ErrorKind {
119124
FailedToInitializeKni(u16),
120125
BadQueue,
121126
CannotSend,
122-
BadDev(std::string::String),
123-
BadVdev(std::string::String),
127+
BadDev(String),
128+
BadVdev(String),
124129
BadTxQueue(u16, u16),
125130
BadRxQueue(u16, u16),
126131
BadOffset(usize),
127132
MetadataTooLarge,
128133
RingAllocationFailure,
129134
InvalidRingSize(usize),
130135
RingDuplicationFailure,
131-
ConfigurationError(std::string::String),
136+
ConfigurationError(String),
132137
NoRunningSchedulerOnCore(i32),
133-
BadSize(usize, std::string::String),
138+
BadSize(usize, String),
134139
BadCharAtIndex(char, usize),
135140
HeaderMismatch,
136141
FailedErrorFormat,
142+
ConfigParseError(String),
137143
}
138144

139-
//TODO improve Display
140145

141146

147+
impl From<AddrParseError> for ErrorKind {
148+
fn from(err: AddrParseError) -> Self {
149+
ErrorKind::ConfigParseError(format!("{}", err))
150+
}
151+
}
152+
153+
impl From<toml::de::Error> for ErrorKind {
154+
fn from(err: toml::de::Error) -> Self {
155+
ErrorKind::ConfigParseError(format!("{}", err))
156+
}
157+
}
158+
159+
impl From<eui48::ParseError> for ErrorKind {
160+
fn from(err: eui48::ParseError) -> Self {
161+
ErrorKind::ConfigParseError(format!("{}", err))
162+
}
163+
}
164+
165+
impl From<ipnet::AddrParseError> for ErrorKind {
166+
fn from(err: ipnet::AddrParseError) -> Self {
167+
ErrorKind::ConfigParseError(format!("{}", err))
168+
}
169+
}
170+
171+
//TODO improve Display
172+
142173
impl Display for ErrorKind {
143174
fn fmt(&self, f: &mut Formatter) -> std::result::Result<(), std::fmt::Error> {
144175
write!(f, "{:?}", self)

framework/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ extern crate net2;
2626
extern crate regex;
2727
extern crate separator;
2828
extern crate twox_hash;
29+
extern crate ipnet;
30+
2931
#[macro_use]
3032
extern crate serde_derive;
3133
extern crate serde;

0 commit comments

Comments
 (0)