Skip to content

Commit

Permalink
Rename TryFromError to TryFromReprError
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Sep 9, 2023
1 parent ebe4319 commit 21b5faf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions impl/src/try_from.rs
Expand Up @@ -165,14 +165,14 @@ impl ToTokens for Expansion {
::core::convert::TryFrom<#repr #ty_generics> for #ident
#where_clause
{
type Error = ::derive_more::TryFromError<#repr>;
type Error = ::derive_more::TryFromReprError<#repr>;

#[inline]
fn try_from(value: #repr) -> ::core::result::Result<Self, Self::Error> {
#(#[allow(non_upper_case_globals)] const #consts: #repr = #discriminants;)*
match value {
#(#consts => ::core::result::Result::Ok(#ident::#variants),)*
_ => ::core::result::Result::Err(::derive_more::TryFromError::new(value)),
_ => ::core::result::Result::Err(::derive_more::TryFromReprError::new(value)),
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/convert.rs
Expand Up @@ -46,19 +46,20 @@ impl<T> fmt::Display for TryIntoError<T> {
#[cfg(feature = "std")]
impl<T: fmt::Debug> std::error::Error for TryIntoError<T> {}

/// Error returned by the derived [`TryFrom`] implementation.
/// Error returned by the derived [`TryFrom`] implementation on enums to
/// convert from their repr.
///
/// [`TryFrom`]: macro@crate::TryFrom
#[derive(Clone, Copy, Debug)]
pub struct TryFromError<T> {
pub struct TryFromReprError<T> {
/// Original input value which failed to convert via the derived
/// [`TryFrom`] implementation.
///
/// [`TryFrom`]: macro@crate::TryFrom
pub input: T,
}

impl<T> TryFromError<T> {
impl<T> TryFromReprError<T> {
#[doc(hidden)]
#[must_use]
#[inline]
Expand All @@ -67,13 +68,13 @@ impl<T> TryFromError<T> {
}
}

// `T` should only be an integer type and therefor display
impl<T: fmt::Display> fmt::Display for TryFromError<T> {
// `T` should only be an integer type and therefor be debug
impl<T: fmt::Debug> fmt::Display for TryFromReprError<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "`{}` does not respond to a unit variant", self.input)
write!(f, "`{:?}` does not respond to a unit variant", self.input)
}
}

#[cfg(feature = "std")]
// `T` should only be an integer type and therefor display and debug
impl<T: fmt::Debug + fmt::Display> std::error::Error for TryFromError<T> {}
// `T` should only be an integer type and therefor be debug
impl<T: fmt::Debug> std::error::Error for TryFromReprError<T> {}
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -94,7 +94,7 @@ pub use crate::r#str::FromStrError;
mod convert;
#[cfg(feature = "try_from")]
#[doc(inline)]
pub use crate::convert::TryFromError;
pub use crate::convert::TryFromReprError;
#[cfg(feature = "try_into")]
#[doc(inline)]
pub use crate::convert::TryIntoError;
Expand Down

0 comments on commit 21b5faf

Please sign in to comment.