Skip to main content

Crate cmn

Crate cmn 

Source
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 — 121 const values (PI, Avogadro, Planck, etc.). With std: runtime Constants lookup API
    • ConstantValue typed enum.
  • macros — 14 utility macros for min/max, range-checks, collections, and parsing.
  • With std feature: words module, datetime utilities, and Common JSON 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

FeatureDefaultEnables
stdYesConstants 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§

pub use constants::Constants;std
pub use words::Words;std

Modules§

constants
121 mathematical, physical, and cryptographic constants as compile-time const values. The const values are always available, even in no_std. The runtime Constants lookup API and ConstantValue enum require the std feature.
datetimestd
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.
wordsstd
A word-list module for passphrase generation and text processing. Backed by HashSet<String> for O(1) lookups with a curated built-in WORD_LIST. Requires std. Word-list management for passphrase generation and text processing.

Macros§

cmnstd
Parses arguments via Common::parse. Requires std.
cmn_assert
Asserts that the given condition is true. Panics with “Assertion failed!” if false.
cmn_constants
Defines a set of f64 constants.
cmn_contains
Checks if a string contains a substring.
cmn_in_range
Checks if a value is within an inclusive range.
cmn_joinstd
Joins strings together into a single String. Requires std.
cmn_mapstd
Creates a HashMap from key-value pairs. Requires std.
cmn_max
Returns the maximum of the given values.
cmn_min
Returns the minimum of the given values.
cmn_parsestd
Parses the given input into a Common value. Requires std.
cmn_printstd
Prints the arguments to stdout. Requires std.
cmn_print_vecstd
Prints each element of a slice to stdout. Requires std.
cmn_splitstd
Splits a string into a Vec<String> by whitespace. Requires std.
cmn_to_num
Converts a string to f64, returning 0.0 on failure.
cmn_vecstd
Creates a new Vec with the given elements. Requires std.

Structs§

Commonstd
The Common structure provides a central location to store data that is commonly used throughout the library. Requires the std feature for serde JSON support.

Functions§

runstd
Main entry point for the Common (CMN) library. Requires std.