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 @@ -410,6 +410,26 @@ pub trait TryInto<T>: Sized {
410
410
/// When the `!` type is stablized `Infallible` and `!` will be
411
411
/// equivalent.
412
412
///
413
+ /// `TryFrom<T>` can be implemented as follows:
414
+ ///
415
+ /// ```
416
+ /// use std::convert::TryFrom;
417
+ ///
418
+ /// struct SuperiorThanZero(i32);
419
+ ///
420
+ /// impl TryFrom<i32> for SuperiorThanZero {
421
+ /// type Error = &'static str;
422
+ ///
423
+ /// fn try_from(value: i32) -> Result<Self, Self::Error> {
424
+ /// if value < 0 {
425
+ /// Err("SuperiorThanZero only accepts value superior than zero!")
426
+ /// } else {
427
+ /// Ok(SuperiorThanZero(value))
428
+ /// }
429
+ /// }
430
+ /// }
431
+ /// ```
432
+ ///
413
433
/// # Examples
414
434
///
415
435
/// As described, [`i32`] implements `TryFrom<i64>`:
You can’t perform that action at this time.
0 commit comments