pub trait TryAsMut<T: ?Sized> {
type Error: Error;
// Required method
fn try_as_mut(&mut self) -> Result<&mut T, Self::Error>;
}Expand description
§Example
let mut a = TestStruct(TestEnum::AType(String::from("a_type")));
let a: Result<&mut str, TestError> = a.try_as_mut();
assert!(a.is_ok());
let mut a: TestStruct = TestStruct(TestEnum::BType(BType()));
let a: Result<&mut str, TestError> = a.try_as_mut();
assert!(a.is_err());
let mut b = TestStruct(TestEnum::BType(BType()));
let b: Result<&mut BType, TestError> = b.try_as_mut();
assert!(b.is_ok());
let mut b = TestStruct(TestEnum::AType(String::from("a_type")));
let b: Result<&mut BType, TestError> = b.try_as_mut();
assert!(b.is_err());Required Associated Types§
Required Methods§
fn try_as_mut(&mut self) -> Result<&mut T, Self::Error>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".