Skip to content

Commit d2117f9

Browse files
committed
Use Error in TryFrom
1 parent 7528230 commit d2117f9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub enum Error {
7575
IntConversion(TryFromIntError),
7676
InvalidUtf8,
7777
UnexpectedNullPtr,
78+
UnknownEnumVariant,
7879
}
7980

8081
impl fmt::Display for Error {
@@ -91,6 +92,7 @@ impl fmt::Display for Error {
9192
f,
9293
"An FFI function call returned a null ptr when we expected a non-null ptr"
9394
),
95+
Error::UnknownEnumVariant => write!(f, "unknown enum variant provided"),
9496
}
9597
}
9698
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,13 @@ macro_rules! from_enum {
257257
}
258258

259259
impl TryFrom<$c_type> for $name {
260-
type Error = ();
260+
type Error = Error;
261261

262262
#[allow(non_upper_case_globals)]
263263
fn try_from(value: $c_type) -> Result<Self, Self::Error> {
264264
match value {
265265
$($value => Ok(Self::$field),)*
266-
_ => Err(())
266+
_ => Err(Error::UnknownEnumVariant)
267267
}
268268
}
269269
}

0 commit comments

Comments
 (0)