NumCast: document when `from` can return `None`

This commit is contained in:
Olivier Chassé St-Laurent 2019-10-18 17:03:59 -04:00
parent 16cdce31d4
commit 27e3f853b0
1 changed files with 2 additions and 1 deletions

View File

@ -639,7 +639,8 @@ pub fn cast<T: NumCast, U: NumCast>(n: T) -> Option<U> {
/// An interface for casting between machine scalars.
pub trait NumCast: Sized + ToPrimitive {
/// Creates a number from another value that can be converted into
/// a primitive via the `ToPrimitive` trait.
/// a primitive via the `ToPrimitive` trait. If the source value cannot be
/// represented by the target type, then `None` is returned.
fn from<T: ToPrimitive>(n: T) -> Option<Self>;
}