min_max_traits

Crates.iomin_max_traits
lib.rsmin_max_traits
version0.1.0
sourcesrc
created_at2022-01-16 08:01:48.412181
updated_at2022-01-16 08:01:48.412181
descriptionTraits for MIN and MAX associated constants
homepage
repositoryhttps://github.com/JohnScience/min_max_traits
max_upload_size
id514675
size18,008
Dmitrii - Demenev (JohnScience)

documentation

https://docs.rs/min_max_traits

README

Traits for MIN and MAX associated constants

At the time of writing, all primitive numeric types in Rust provide MIN and MAX associated constants, which nonetheless do not belong to any trait.

One commonly used crate, num-traits, offers many useful traits for numeric types. However, the closest analogue of min_max_traits::Min and min_max_traits::Max offered by num-traits at the time of writing is num_traits::Bounded, which requires implementation of min_value() and max_value() functions. Since const_fn_trait_bound feature is in the works, num_traits::Bounded cannot be used in generic implementations of constant functions relying on MIN and MAX associated constants, at least on stable Rust.

These traits can be useful, for example, to generically implement associated constants storing the greatest length of primitive integers when converted to strings.

Excerpt from Rust's reference:

Numeric types

Integer types

The unsigned integer types consist of:

Type Minimum Maximum

u8 | 0 | 28-1 u16 | 0 | 216-1 u32 | 0 | 232-1 u64 | 0 | 264-1 u128 | 0 | 2128-1

The signed two's complement integer types consist of:

Type Minimum Maximum

i8 | -(27) | 27-1 i16 | -(215) | 215-1 i32 | -(231) | 231-1 i64 | -(263) | 263-1 i128 | -(2127) | 2127-1

Floating-point types

The IEEE 754-2008 "binary32" and "binary64" floating-point types are f32 and f64, respectively.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 2

cargo fmt