Skip to content

Commit

Permalink
Remove derivative dependency (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeledfyr committed Dec 31, 2021
1 parent ed79692 commit 98a63bc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion num_enum/Cargo.toml
Expand Up @@ -29,7 +29,6 @@ travis-ci = { repository = "illicitonion/num_enum", branch = "master" }
maintenance = { status = "passively-maintained" }

[dependencies]
derivative = { version = "2", features = ["use_core"] }
num_enum_derive = { version = "0.5.5", path = "../num_enum_derive", default-features = false }

[dev-dependencies]
Expand Down
29 changes: 21 additions & 8 deletions num_enum/src/lib.rs
Expand Up @@ -27,18 +27,31 @@ pub trait TryFromPrimitive: Sized {
fn try_from_primitive(number: Self::Primitive) -> Result<Self, TryFromPrimitiveError<Self>>;
}

#[derive(::derivative::Derivative)]
#[derivative( // use derivative to remove incorrect bound on `Enum` parameter. See https://github.com/rust-lang/rust/issues/26925
Debug(bound = ""),
Clone(bound = ""),
Copy(bound = ""),
PartialEq(bound = ""),
Eq(bound = "")
)]
pub struct TryFromPrimitiveError<Enum: TryFromPrimitive> {
pub number: Enum::Primitive,
}

impl<Enum: TryFromPrimitive> Copy for TryFromPrimitiveError<Enum> {}
impl<Enum: TryFromPrimitive> Clone for TryFromPrimitiveError<Enum> {
fn clone(&self) -> Self {
TryFromPrimitiveError {
number: self.number,
}
}
}
impl<Enum: TryFromPrimitive> Eq for TryFromPrimitiveError<Enum> {}
impl<Enum: TryFromPrimitive> PartialEq for TryFromPrimitiveError<Enum> {
fn eq(&self, other: &Self) -> bool {
self.number == other.number
}
}
impl<Enum: TryFromPrimitive> fmt::Debug for TryFromPrimitiveError<Enum> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("TryFromPrimitiveError")
.field("number", &self.number)
.finish()
}
}
impl<Enum: TryFromPrimitive> fmt::Display for TryFromPrimitiveError<Enum> {
fn fmt(&self, stream: &'_ mut fmt::Formatter<'_>) -> fmt::Result {
write!(
Expand Down

0 comments on commit 98a63bc

Please sign in to comment.