Expand description
§num-primitive
Traits for primitive numeric types in Rust.
These traits provide a simple hierarchy for generic programming with Rust’s primitive floating-point and integer types:
PrimitiveNumberPrimitiveFloat:f32andf64PrimitiveIntegerPrimitiveSigned:i8,i16,i32,i64,i128, andisizePrimitiveUnsigned:u8,u16,u32,u64,u128, andusize
Each trait includes supertraits for everything implemented in common by these
types, as well as associated constants and methods matching their inherent
items. PrimitiveFloat also adds the contents of core::{float}::consts.
It is not a goal of this crate to add any functionality to the primitive types, only to expose what is already available in the standard library in a more generic way. The traits are also sealed against downstream implementations to allow expansion in a non-breaking way.
For use-cases that include third-party types, along with features that go beyond
the standard library, consider crates like num-traits and num-integer.
§Usage
Add this to your Cargo.toml:
[dependencies]
num-primitive = "0.1"§Features
This crate can be used without the standard library (#![no_std]) by disabling
the default std feature. Use this in Cargo.toml:
[dependencies.num-primitive]
version = "0.1"
default-features = falseSome PrimitiveFloat methods are only available when the std feature is
enabled, just like when using those floating-point types directly.
Traits§
- Primitive
Error - Trait for errors that may be returned in numeric conversions.
- Primitive
Float - Trait for all primitive floating-point types, including the supertrait
PrimitiveNumber. - Primitive
Float Ref - Trait for references to primitive floating-point types (
PrimitiveFloat). - Primitive
Float ToInt - Trait for conversions supported by
PrimitiveFloat::to_int_unchecked. - Primitive
Integer - Trait for all primitive integer types, including the supertrait
PrimitiveNumber. - Primitive
Integer Ref - Trait for references to primitive integer types (
PrimitiveInteger). - Primitive
Number - Trait for all primitive numeric types.
- Primitive
Number Ref - Trait for references to primitive numbers (
PrimitiveNumber). - Primitive
Signed - Trait for all primitive signed integer types, including the supertraits
PrimitiveIntegerandPrimitiveNumber. - Primitive
Signed Ref - Trait for references to primitive signed integer types (
PrimitiveSigned). - Primitive
Unsigned - Trait for all primitive unsigned integer types, including the supertraits
PrimitiveIntegerandPrimitiveNumber. - Primitive
Unsigned Ref - Trait for references to primitive unsigned integer types (
PrimitiveUnsigned).