Trait easy_cast::Conv [−][src]
Like From
, but supporting potentially-fallible conversions
This trait is intended to replace many uses of the as
keyword for
numeric conversions, though not all.
Conversions from floating-point types are excluded since it is very easy to
(accidentally) produce non-integer values; instead use ConvFloat
.
Two methods are provided:
Conv::conv
is for “success expected” conversions. In debug builds and when using thealways_assert
feature flag, inexact conversions will panic. In other cases, conversions may produce incorrect values (according to the behaviour ofas
). This is similar to the behviour of Rust’s overflow checks on integer arithmetic, and intended for usage when the user is “reasonably sure” that conversion will succeed.Conv::try_conv
is for fallible conversions, and always produces an error if the conversion would be inexact.
Required methods
fn conv(v: T) -> Self
[src]
Convert from T
to Self
fn try_conv(v: T) -> Result<Self, Error>
[src]
Try converting from T
to Self