Rollup merge of #59707 - GuillaumeGomez:GuillaumeGomez-patch-1, r=Centril

Add missing tryfrom example

r? @rust-lang/docs
This commit is contained in:
Mazdak Farrokhzad 2019-04-06 00:14:46 +02:00 committed by GitHub
commit c065367ca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -429,6 +429,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>`: