Expand description
§Common (CMN)
121 mathematical and cryptographic constants for Rust.
Zero runtime cost. no_std compatible.
§Why CMN?
std::f64::consts provides 11 mathematical constants. CMN
extends that with 44 physical, cryptographic, and series
constants — plus a runtime lookup API, 14 utility macros,
and a built-in word-list module. Every constant resolves at
compile time. Works in no_std environments.
§Modules
constants— 121constvalues (PI, Avogadro, Planck, etc.). Withstd: runtimeConstantslookup APIConstantValuetyped enum.
macros— 14 utility macros for min/max, range-checks, collections, and parsing.- With
stdfeature:wordsmodule,datetimeutilities, andCommonJSON bridge.
§Quick Start
// Compile-time constants — always available, even in no_std
use cmn::constants::{PI, EULER, SPEED_OF_LIGHT};
assert_eq!(PI, core::f64::consts::PI);// Runtime lookup — requires the `std` feature (default)
use cmn::Constants;
use cmn::Words;
use cmn::words::WORD_LIST;
let constants = Constants::new();
let euler = constants.constant("EULER").unwrap();
assert_eq!(euler.name, "EULER");
let words = Words::default();
let list = words.words_list();
assert_eq!(list.len(), WORD_LIST.len());
assert_eq!(list[0], "aboard");§Feature Flags
| Feature | Default | Enables |
|---|---|---|
std | Yes | Constants struct, Words, Common, serde support |
For no_std, disable default features:
[dependencies]
cmn = { version = "0.0.6", default-features = false }§License
Dual-licensed under Apache 2.0 or MIT, at your option.
Re-exports§
Modules§
- constants
- 121 mathematical, physical, and cryptographic constants as
compile-time
constvalues. Theconstvalues are always available, even inno_std. The runtimeConstantslookup API andConstantValueenum require thestdfeature. - datetime
std - Lightweight datetime utilities for ISO 8601 parsing,
relative time formatting, and duration calculations.
No external datetime crate required. Requires
std. Lightweight datetime utilities for ISO 8601 parsing, relative time formatting, and duration calculations. - macros
- 14 utility macros for assertions, collections, range-checks,
and string operations. Available in
no_std. Utility macros that eliminate common Rust boilerplate. - words
std - A word-list module for passphrase generation and text
processing. Backed by
HashSet<String>for O(1) lookups with a curated built-inWORD_LIST. Requiresstd. Word-list management for passphrase generation and text processing.
Macros§
- cmn
std - Parses arguments via
Common::parse. Requiresstd. - cmn_
assert - Asserts that the given condition is true. Panics with “Assertion failed!” if false.
- cmn_
constants - Defines a set of
f64constants. - cmn_
contains - Checks if a string contains a substring.
- cmn_
in_ range - Checks if a value is within an inclusive range.
- cmn_
join std - Joins strings together into a single
String. Requiresstd. - cmn_map
std - Creates a
HashMapfrom key-value pairs. Requiresstd. - cmn_max
- Returns the maximum of the given values.
- cmn_min
- Returns the minimum of the given values.
- cmn_
parse std - Parses the given input into a
Commonvalue. Requiresstd. - cmn_
print std - Prints the arguments to stdout. Requires
std. - cmn_
print_ vec std - Prints each element of a slice to stdout.
Requires
std. - cmn_
split std - Splits a string into a
Vec<String>by whitespace. Requiresstd. - cmn_
to_ num - Converts a string to
f64, returning0.0on failure. - cmn_vec
std - Creates a new
Vecwith the given elements. Requiresstd.
Structs§
- Common
std - The
Commonstructure provides a central location to store data that is commonly used throughout the library. Requires thestdfeature for serde JSON support.
Functions§
- run
std - Main entry point for the
Common (CMN)library. Requiresstd.