We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4c27fb1 commit c386210Copy full SHA for c386210
src/libcore/convert.rs
@@ -410,6 +410,26 @@ pub trait TryInto<T>: Sized {
410
/// When the `!` type is stablized `Infallible` and `!` will be
411
/// equivalent.
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
433
/// # Examples
434
435
/// As described, [`i32`] implements `TryFrom<i64>`:
0 commit comments