Skip to content
Permalink
Browse files

Add missing tryfrom example

  • Loading branch information...
GuillaumeGomez committed Mar 29, 2019
1 parent 4c27fb1 commit c3862107145d245d30aaa7085aa6ade38faff8c1
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/libcore/convert.rs
@@ -410,6 +410,26 @@ pub trait TryInto<T>: Sized {
/// When the `!` type is stablized `Infallible` and `!` will be
/// equivalent.
///
/// `TryFrom<T>` can be implemented as follows:
///
/// ```
/// use std::convert::TryFrom;
///
/// struct SuperiorThanZero(i32);
///
/// impl TryFrom<i32> for SuperiorThanZero {
/// type Error = &'static str;
///
/// fn try_from(value: i32) -> Result<Self, Self::Error> {
/// if value < 0 {
/// Err("SuperiorThanZero only accepts value superior than zero!")
/// } else {
/// Ok(SuperiorThanZero(value))
/// }
/// }
/// }
/// ```
///
/// # Examples
///
/// As described, [`i32`] implements `TryFrom<i64>`:

0 comments on commit c386210

Please sign in to comment.
You can’t perform that action at this time.