We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents b14662f + c386210 commit d2936c3Copy full SHA for d2936c3
src/libcore/convert.rs
@@ -429,6 +429,26 @@ pub trait TryInto<T>: Sized {
429
/// When the `!` type is stablized `Infallible` and `!` will be
430
/// equivalent.
431
///
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
452
/// # Examples
453
454
/// As described, [`i32`] implements `TryFrom<i64>`:
0 commit comments