File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -429,6 +429,26 @@ pub trait TryInto<T>: Sized {
429429/// When the `!` type is stablized `Infallible` and `!` will be
430430/// equivalent.
431431///
432+ /// `TryFrom<T>` can be implemented as follows:
433+ ///
434+ /// ```
435+ /// use std::convert::TryFrom;
436+ ///
437+ /// struct SuperiorThanZero(i32);
438+ ///
439+ /// impl TryFrom<i32> for SuperiorThanZero {
440+ /// type Error = &'static str;
441+ ///
442+ /// fn try_from(value: i32) -> Result<Self, Self::Error> {
443+ /// if value < 0 {
444+ /// Err("SuperiorThanZero only accepts value superior than zero!")
445+ /// } else {
446+ /// Ok(SuperiorThanZero(value))
447+ /// }
448+ /// }
449+ /// }
450+ /// ```
451+ ///
432452/// # Examples
433453///
434454/// As described, [`i32`] implements `TryFrom<i64>`:
You can’t perform that action at this time.
0 commit comments