Trait mz_ore::cast::TryCastFrom

source ·
pub trait TryCastFrom<T>: Sized {
    // Required method
    fn try_cast_from(from: T) -> Option<Self>;
}
Expand description

A trait for attempted casts.

TryCast is like as, but returns None if the conversion can’t be round-tripped.

Note: there may be holes in the domain of try_cast_from, which is probably why TryFrom wasn’t implemented for floats in the standard library. For example, i64::MAX can be converted to f64, but i64::MAX - 1 can’t.

Required Methods§

source

fn try_cast_from(from: T) -> Option<Self>

Attempts to perform the cast

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TryCastFrom<f64> for i64

source§

impl TryCastFrom<f64> for u64

source§

impl TryCastFrom<i64> for f64

source§

impl TryCastFrom<u64> for f64

Implementors§