Numeric casts
This crate provides checked, overflowing and static casts.
Quick examples
use Wrapping;
// Panics on overflow with `debug_assertions`, otherwise wraps.
let a: u32 = cast;
assert_eq!;
// Always wraps.
let b: u32 = wrapping_cast;
assert_eq!;
let c = ;
assert_eq!;
// Wrapping can also be obtained using `Wrapping`
let d: = cast;
assert_eq!;
Conversions from floating-point to integers are also supported.
Numbers are rounded towards zero, but the Round
wrapper can be
used to convert floating-point numbers to integers with rounding to
the nearest, with ties rounded to even.
use Round;
use f32;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Using the az crate
The az crate is available on crates.io. To use it in your crate, add it as a dependency inside Cargo.toml:
[]
= "0.1.0"
License
This crate is free software: you can redistribute it and/or modify it under the terms of either
- the Apache License, Version 2.0 or
- the MIT License
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache License, Version 2.0, shall be dual licensed as above, without any additional terms or conditions.