Skip to content

Commit

Permalink
Add missing tryfrom example
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez authored Mar 29, 2019
1 parent 4c27fb1 commit 645d95e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,24 @@ pub trait TryInto<T>: Sized {
/// When the `!` type is stablized `Infallible` and `!` will be
/// equivalent.
///
/// It can be implemented as follows:
///
/// ```
/// 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>`:
Expand Down

0 comments on commit 645d95e

Please sign in to comment.