num-t

Crates.ionum-t
lib.rsnum-t
version3.0.0
created_at2025-04-25 21:55:32.871925+00
updated_at2025-04-26 11:56:50.296923+00
descriptionNum: Associate arbitrary types with numeric types
homepage
repositoryhttps://github.com/frewsxcv/num-t
max_upload_size
id1649558
size23,704
Corey Farwell (frewsxcv)

documentation

README

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: Implements float_next_after::NextAfter for Num when the underlying Number type also implements it.
  • geo: Implements geo::GeoNum for Num when the underlying Number type also implements it.

License

This crate is licensed under either of

  • Apache License, Version 2.0
  • MIT license

at your option.

Commit count: 5

cargo fmt