3 stable releases
new 3.0.0 | Apr 26, 2025 |
---|---|
2.0.0 | Apr 25, 2025 |
1.0.0 | Apr 25, 2025 |
#307 in Rust patterns
73 downloads per month
15KB
421 lines
num-t
Num<T>
: Associate arbitrary types with numeric types
This crate provides the Num<Number, Type>
struct, which allows you to associate an arbitrary type Type
with a numeric value Number
. This can be useful for creating strongly-typed numeric values, preventing mixing of different units or concepts in calculations.
Num<Number, Type>
wraps a numeric type Number
and uses a std::marker::PhantomData<Type>
to carry the type information without adding runtime overhead.
It implements many standard traits, including:
Clone
,Copy
,Default
From<Scalar>
PartialOrd
,PartialEq
,Eq
- Arithmetic operators (
Add
,Sub
,Mul
,Div
,Rem
,AddAssign
, etc.) FromStr
,Display
Sum
- Traits from the
num-traits
crate:ToPrimitive
,NumCast
,Num
,One
,Zero
,Float
,Bounded
,Signed
,FromPrimitive
.
Optional Features
float_next_after
: Implementsfloat_next_after::NextAfter
forNum
when the underlyingNumber
type also implements it.geo
: Implementsgeo::GeoNum
forNum
when the underlyingNumber
type also implements it.
License
This crate is licensed under either of
- Apache License, Version 2.0
- MIT license
at your option.
Dependencies
~0–1.5MB
~26K SLoC