//! Definitions used in derived implementations of [`core::convert`] traits. use core::fmt; /// Error returned by the derived [`TryInto`] implementation. /// /// [`TryInto`]: macro@crate::TryInto #[derive(Clone, Copy, Debug)] pub struct TryIntoError { /// Original input value which failed to convert via the derived /// [`TryInto`] implementation. /// /// [`TryInto`]: macro@crate::TryInto pub input: T, variant_names: &'static str, output_type: &'static str, } impl TryIntoError { #[doc(hidden)] #[must_use] #[inline] pub const fn new( input: T, variant_names: &'static str, output_type: &'static str, ) -> Self { Self { input, variant_names, output_type, } } } impl fmt::Display for TryIntoError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Only {} can be converted to {}", self.variant_names, self.output_type, ) } } #[cfg(feature = "std")] impl std::error::Error for TryIntoError {}