diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 7b9e19e36a29..e903bd936c48 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -429,6 +429,26 @@ pub trait TryInto: Sized { /// When the `!` type is stablized `Infallible` and `!` will be /// equivalent. /// +/// `TryFrom` can be implemented as follows: +/// +/// ``` +/// use std::convert::TryFrom; +/// +/// struct SuperiorThanZero(i32); +/// +/// impl TryFrom for SuperiorThanZero { +/// type Error = &'static str; +/// +/// fn try_from(value: i32) -> Result { +/// if value < 0 { +/// Err("SuperiorThanZero only accepts value superior than zero!") +/// } else { +/// Ok(SuperiorThanZero(value)) +/// } +/// } +/// } +/// ``` +/// /// # Examples /// /// As described, [`i32`] implements `TryFrom`: