num_primitive/lib.rs
1//! # num-primitive
2//!
3//! Traits for primitive numeric types in Rust.
4//!
5//! These traits provide a simple hierarchy for generic programming with Rust's
6//! primitive floating-point and integer types:
7//!
8//! * [`PrimitiveNumber`]
9//! * [`PrimitiveFloat`]: `f32` and `f64`
10//! * [`PrimitiveInteger`]
11//! * [`PrimitiveSigned`]: `i8`, `i16`, `i32`, `i64`, `i128`, and `isize`
12//! * [`PrimitiveUnsigned`]: `u8`, `u16`, `u32`, `u64`, `u128`, and `usize`
13//!
14//! Each trait includes supertraits for everything implemented in common by these
15//! types, as well as associated constants and methods matching their inherent
16//! items. `PrimitiveFloat` also adds the contents of `core::{float}::consts`.
17//!
18//! It is not a goal of this crate to *add* any functionality to the primitive
19//! types, only to expose what is already available in the standard library in a
20//! more generic way. The traits are also [sealed] against downstream
21//! implementations to allow expansion in a non-breaking way.
22//!
23//! For use-cases that include third-party types, along with features that go beyond
24//! the standard library, consider crates like [`num-traits`] and [`num-integer`].
25//!
26//! [`num-integer`]: https://crates.io/crates/num-integer
27//! [`num-traits`]: https://crates.io/crates/num-traits
28//! [sealed]: https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed
29//!
30//! ## Usage
31//!
32//! Add this to your `Cargo.toml`:
33//!
34//! ```toml
35//! [dependencies]
36//! num-primitive = "0.1"
37//! ```
38//!
39//! ## Features
40//!
41//! This crate can be used without the standard library (`#![no_std]`) by disabling
42//! the default `std` feature. Use this in `Cargo.toml`:
43//!
44//! ```toml
45//! [dependencies.num-primitive]
46//! version = "0.1"
47//! default-features = false
48//! ```
49//!
50//! Some `PrimitiveFloat` methods are only available when the `std` feature is
51//! enabled, just like when using those floating-point types directly.
52
53#![no_std]
54#![cfg_attr(docsrs, feature(doc_cfg))]
55
56#[cfg(feature = "std")]
57extern crate std;
58
59#[macro_use]
60mod macros;
61
62mod error;
63mod float;
64mod integer;
65mod number;
66mod signed;
67mod unsigned;
68
69#[cfg(test)]
70mod tests;
71
72pub use self::error::PrimitiveError;
73pub use self::float::{PrimitiveFloat, PrimitiveFloatRef, PrimitiveFloatToInt};
74pub use self::integer::{PrimitiveInteger, PrimitiveIntegerRef};
75pub use self::number::{PrimitiveNumber, PrimitiveNumberRef};
76pub use self::signed::{PrimitiveSigned, PrimitiveSignedRef};
77pub use self::unsigned::{PrimitiveUnsigned, PrimitiveUnsignedRef};