We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4c27fb1 commit 645d95eCopy full SHA for 645d95e
src/libcore/convert.rs
@@ -410,6 +410,24 @@ pub trait TryInto<T>: Sized {
410
/// When the `!` type is stablized `Infallible` and `!` will be
411
/// equivalent.
412
///
413
+/// It can be implemented as follows:
414
+///
415
+/// ```
416
+/// struct SuperiorThanZero(i32);
417
418
+/// impl TryFrom<i32> for SuperiorThanZero {
419
+/// type Error = &'static str;
420
421
+/// fn try_from(value: i32) -> Result<Self, Self::Error> {
422
+/// if value < 0 {
423
+/// Err("SuperiorThanZero only accepts value superior than zero!")
424
+/// } else {
425
+/// Ok(SuperiorThanZero(value))
426
+/// }
427
428
429
430
431
/// # Examples
432
433
/// As described, [`i32`] implements `TryFrom<i64>`:
0 commit comments