numeric_constant_traits

Crates.ionumeric_constant_traits
lib.rsnumeric_constant_traits
version0.1.1
sourcesrc
created_at2023-09-08 16:08:26.498519
updated_at2023-09-08 16:14:16.955087
descriptionTraits for generic numeric constants
homepage
repositoryhttps://github.com/PanieriLorenzo/numeric_constant_traits/tree/main
max_upload_size
id967279
size14,689
(PanieriLorenzo)

documentation

https://docs.rs/numeric_constant_traits

README

numeric_constant_traits

Traits for generic numeric constants

Like the traits Zero and One from the num crate, but for all natural numbers up to and including 100. Allows doing generic arithmetic without having to do casts.

Without this crate you'd need to do something like:

2u8.into() * 3u8.into() + 4u8.into()

Which is okay, but obfuscates a bit what the intent is.

With this crate you can do something like this:

T::two() * T::three() + T::four()

The traits are implemented for all standard numeric types, as well as a blanket implementation for num::Complex<T>, where T is any of the standar numeric types.

Commit count: 0

cargo fmt