# Numeric casts
This crate provides casts and checked casts.
# What’s new
### Version 0.3.1 news (2020-04-17)
* Static casts were deprecated as their use case was unclear.
### Version 0.3.0 news (2019-10-01)
* The behavior of static casts was changed: now they return
[`Option`], but an implementation should either always return
[`Some`] or always return [`None`].
* Bug fix: checked casts from floating-point to wrapped integers
were panicking for infinite or NaN.
[`None`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.None
[`Option`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html
[`Some`]: https://doc.rust-lang.org/nightly/core/option/enum.Option.html#variant.Some
## Quick examples
```rust
use az::{Az, OverflowingAs, WrappingAs};
use core::num::Wrapping;
// Panics on overflow with `debug_assertions`, otherwise wraps
assert_eq!(12i32.az::<u32>(), 12u32);
// Always wraps
let wrapped = 1u32.wrapping_neg();
assert_eq!((-1).wrapping_as::<u32>(), wrapped);
assert_eq!((-1).overflowing_as::<u32>(), (wrapped, true));
// Wrapping can also be obtained using `Wrapping`
assert_eq!((-1).az::<Wrapping<u32>>().0, wrapped);
```
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.
```rust
use az::{Az, CheckedAs, Round, SaturatingAs};
use core::f32;
assert_eq!(15.7.az::<i32>(), 15);
assert_eq!(Round(15.5).az::<i32>(), 16);
assert_eq!(1.5e20.saturating_as::<i32>(), i32::max_value());
assert_eq!(f32::NAN.checked_as::<i32>(), None);
```
## Using the *az* crate
The *az* crate is available on [crates.io][*az* crate]. To use it in
your crate, add it as a dependency inside [*Cargo.toml*]:
```toml
[dependencies]
az = "0.3.1"
```
## 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][LICENSE-APACHE] or
* the [MIT License][LICENSE-MIT]
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.
[*Cargo.toml*]: https://doc.rust-lang.org/cargo/guide/dependencies.html
[*az* crate]: https://crates.io/crates/az
[LICENSE-APACHE]: https://www.apache.org/licenses/LICENSE-2.0
[LICENSE-MIT]: https://opensource.org/licenses/MIT
[`Round`]: https://docs.rs/az/0.3.1/az/struct.Round.html