pub trait UnwrappedCastFrom<Src> {
// Required method
fn unwrapped_cast_from(src: Src) -> Self;
}
Expand description
Used to cast values, panicking if the value does not fit.
This trait enables trait constraints for casting in the opposite direction to
UnwrappedCast
.
§Examples
use az::UnwrappedCastFrom;
trait Tr {
type Assoc: UnwrappedCastFrom<u8>;
fn unwrapped_assoc_from_u8(a: u8) -> Self::Assoc {
UnwrappedCastFrom::unwrapped_cast_from(a)
}
}
impl Tr for () {
type Assoc = i8;
}
assert_eq!(<() as Tr>::unwrapped_assoc_from_u8(5u8), 5i8);
The following assertion would panic because of overflow.
ⓘ
let _overflow = <() as Tr>::unwrapped_assoc_from_u8(255u8);
Required Methods§
sourcefn unwrapped_cast_from(src: Src) -> Self
fn unwrapped_cast_from(src: Src) -> Self
Casts the value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.