You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
121 mathematical and physical constants for Rust. Zero runtime cost. no_std compatible.
What is CMN?
CMN gives you accurate, well-documented mathematical and physical constants as compile-time const values in Rust. Every constant resolves at compile time with zero runtime allocation.
One line to install. Zero configuration. 295 tests. 100% code coverage.
DateTime::parse("2026-04-05T14:30:00Z") — zero deps
Word list for passphrase generation
Find a dictionary crate or embed your own
Words::default() — curated, deduplicated, sorted
How CMN compares to other constants crates
cmn
physical_constants
natural_constants
std::f64::consts
Constants
121
354
370+
11
Runtime typed lookup
ConstantValue enum
--
--
--
Category filtering
Category enum
--
--
--
no_std support
Yes
No
No
Yes
WASM support
Yes
Unknown
Unknown
Yes
Utility macros
15 (7 no_std + 8 std)
--
--
--
Datetime module
Built-in
--
--
--
Word list
Built-in
--
--
--
License
MIT / Apache-2.0
GPL-3.0
MIT
stdlib
Test coverage
100% (295 tests)
Unknown
Unknown
N/A
Documentation
100%
100%
29%
stdlib
MSRV
1.72
Unspecified
Unspecified
N/A
physical_constants has the most values but is GPL-3.0 — incompatible with MIT/Apache projects. natural_constants spans the most disciplines but is 29% documented and stale since 2022. CMN is the only crate combining constants, typed runtime lookup, category filtering, no_std/WASM support, utility macros, a datetime module, and a word list under a permissive license with 100% test coverage.
Install
Add to Cargo.toml:
[dependencies]
cmn = "0.0.6"
For no_std (constants + 7 macros only, zero dependencies):
cmn = { version = "0.0.6", default-features = false }
Requires Rust 1.72+. Works on macOS, Linux, Windows, and WASM.
// These work in no_std:use cmn::{cmn_max, cmn_min, cmn_in_range};let max = cmn_max!(3,7,2);// 7let min = cmn_min!(3,7,2);// 2let ok = cmn_in_range!(5,0,10);// true
// These require the std feature (default):use cmn::{cmn_vec, cmn_map, cmn_join};let v = cmn_vec!(1,2,3);let m = cmn_map!("a" => 1,"b" => 2);let s = cmn_join!("hello"," ","world");
Word List (std)
use cmn::Words;let words = Words::default();println!("{} words loaded", words.count());println!("First: {}", words.words_list()[0]);// "aboard"
Datetime (std)
use cmn::datetime::DateTime;let dt = DateTime::parse("2026-04-05T14:30:00Z").unwrap();let dt2 = DateTime::parse("2026-04-05T16:30:00Z").unwrap();println!("{}", dt2.duration_since(&dt).whole_hours());// 2println!("{}", dt.relative_to(&dt2));// "2 hours ago"let now = DateTime::now();let tomorrow = now.add_days(1);
graph LR
subgraph "cmn crate"
B["constants.rs<br/>121 const values<br/>Constants lookup API<br/>Category filtering"]
C["words.rs<br/>Words HashSet<br/>WORD_LIST dictionary"]
D["macros.rs<br/>15 utility macros<br/>(7 no_std + 8 std)"]
E["datetime.rs<br/>ISO 8601 parsing<br/>Duration & relative time"]
A["lib.rs<br/>Common struct<br/>JSON serde bridge"]
end
A --> B
A --> C
A --> D
A --> E
U["Your Code"] --> B
U --> C
U --> D
U --> E
U --> A
Without std: all 121 const values, CONSTANTS_TABLE with Category, and 7 no_std macros — with zero dependencies.
FAQ
How accurate are the constants?
Mathematical constants use core::f64::consts where available (PI, E, TAU, SQRT2). Physical constants are sourced from CODATA 2018 recommended values. Boson masses are from PDG 2022. All values are validated by 295 tests including mathematical identity checks (e.g., SQRT2^2 == 2, R == k_B * N_A, Phi_0 == h/(2e)).
Does CMN support no_std?
Yes. Disable default features to get all 121 const values, CONSTANTS_TABLE with Category filtering, and 7 macros with zero dependencies:
cmn = { version = "0.0.6", default-features = false }
The Constants runtime API, Words, Common, datetime, and 8 std macros require the std feature (enabled by default).
Does CMN compile to WASM?
Yes. cargo build --target wasm32-unknown-unknown --no-default-features compiles cleanly.
What is the MSRV?
Rust 1.72. Tested on stable. No nightly features required.
How does CMN compare to other Rust constants crates?physical_constants has 354 values but is GPL-3.0 — incompatible with MIT/Apache projects. natural_constants covers more disciplines but is only 29% documented and unmaintained since 2022. std::f64::consts provides 11 math constants with no physical values. CMN is the only crate combining 121 constants with typed runtime lookup, category filtering, no_std/WASM support, 15 utility macros, a datetime module, and a word list under a permissive license with 100% test coverage. See the comparison table above.
Development
Prerequisites
Platform
Install Rust
macOS
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Linux / WSL
Same as above, plus sudo apt-get install -y build-essential
cargo run --example cmn
cargo run --example constants_math
cargo run --example constants_physical
cargo run --example constants_lookup
cargo run --example datetime_demo
cargo run --example words_demo
cargo run --example macros_demo