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 9a63f3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion impl/src/try_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ 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> {
Expand Down
17 changes: 9 additions & 8 deletions src/convert.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9a63f3e

Please sign in to comment.