try_traits/convert.rs
1//! Try traits for [`core::convert`].
2//!
3//! Note that [`TryFrom`](core::convert::TryFrom) and [`TryInto`](core::convert::TryInto) are
4//! missing, as they're already a part of the core library.
5
6/// The try trait for [`AsRef`].
7pub trait TryAsRef<T: ?Sized> {
8 /// The type returned in the event of an error.
9 type Error;
10
11 /// The fallible equivalent of [`AsRef::as_ref`].
12 fn try_as_ref(&self) -> Result<&T, Self::Error>;
13}
14
15/// The try trait for [`AsMut`].
16pub trait TryAsMut<T: ?Sized> {
17 /// The type returned in the event of an error.
18 type Error;
19
20 /// The fallible equivalent of [`AsMut::as_mut`].
21 fn try_as_mut(&mut self) -> Result<&mut T, Self::Error>;
22}