Expand description
A Rust library for accessing a collection of mathematical and cryptographic constants
Part of the Mini Functions family of libraries.
Overview 📖
Common (CMN)
is a modern, fast, and user-friendly library that makes it easy to access a wide range of mathematical and cryptographic constants.
Features ✨
The Common (CMN)
uses the serde
crate to serialize and deserialize the data.
The library has three modules:
- Macros: This module contains functions for generating macros that can be used to access the constants.
- Constants: This module contains the Constants structure, which provides a collection of constant values that are used throughout the library.
- Words: This module contains the Words structure, which provides a collection of words that are used throughout the library.
Mathematical and Cryptographic Constants
The following table lists the most important mathematical and cryptographic constants available in the Common (CMN)
library:
Constants | Description | Example |
---|---|---|
AVOGADRO | Avogadro’s constant is the number of atoms or molecules in one mole of a substance. | The number of atoms in 12 grams of carbon-12 is 6.02214076 × 10^23. This can be used to calculate the number of atoms or molecules in a given sample. |
BOLTZMANN | Boltzmann’s constant is the physical constant relating the temperature of a system to the average kinetic energy of its constituent particles. | The kinetic energy of an atom at room temperature is about 2.0 × 10^-21 joules. This can be used to calculate the temperature of a system, or to calculate the average kinetic energy of its particles. |
EULER | Euler’s constant is a mathematical constant approximately equal to 2.71828. | The sum of the infinite series 1 + 1/2 + 1/3 + … is equal to Euler’s constant, e. This can be used to calculate the sum of an infinite series, or to calculate the logarithm of a number. |
GAMMA | The gamma constant is a mathematical constant approximately equal to 0.57721. | The gamma function of 2 is equal to 1. This can be used to calculate the gamma function of a number, or to calculate the factorial of a number. |
HASH_ALGORITHM | The hash algorithm used to generate the hash. The default is Blake3. | The hash of the string “Hello, world!” is 5eb63bbbe01eeed093cb22bb8f5acdc32790160b123138d53f2173b8d3dc3eee. This can be used to verify the integrity of data, or to create a unique identifier for a file. |
HASH_COST | The cost of the hash. | The hash cost of Blake3 is 2^128. This can be used to determine how secure a hash algorithm is. |
HASH_LENGTH | The length of the hash. | The hash length of Blake3 is 32 bytes. This can be used to determine how much space is required to store the hash output. |
PHI | The golden ratio is a number approximately equal to 1.618033988749895. | The golden ratio can be used to create a symmetrical design, or a design that is pleasing to the eye. |
PI | Pi is the ratio of a circle’s circumference to its diameter. | The circumference of a circle with a radius of 1 is equal to pi. This can be used to calculate the circumference, area, and volume of circles, spheres, and other geometric shapes. |
PLANCK | Planck’s constant is a physical constant that is approximately equal to 6.62607015 × 10^−34 joule seconds. | The energy of a photon of light with a wavelength of 500 nanometers is equal to Planck’s constant multiplied by the frequency of the light. This can be used to calculate the energy of photons and other elementary particles. |
SILVER_RATIO | The silver ratio is a number approximately equal to 1.414213562373095. | The silver ratio can be used to create a symmetrical design, or a design that is pleasing to the eye. |
SPECIAL_CHARS | A list of special characters. | The special characters are: !@#$%^&*()_+-={}[] |
SQRT2 | The square root of 2 is a number approximately equal to 1.414213562373095. | The area of a circle with a radius of 1 is equal to the square root of 2. This can be used to calculate the area and volume of circles, spheres, and other geometric shapes. |
SQRT3 | The square root of 3 is a number approximately equal to 1.732050807568877. | The area of a circle with a radius of 1 is equal to the square root of 3. This can be used to calculate the area and volume of circles |
SQRT5 | The square root of 5 is a number approximately equal to 2.23606797749979. | The area of a circle with a radius of 1 is equal to the square root of 5. |
TAU | Tau is a number approximately equal to 6.283185307179586. | The circumference of a circle with a radius of 1 is equal to tau. |
The following table lists the dictionaries available in the Common library.
Words | Description |
---|---|
words | Contains a dictionary of common words. |
Usage
Common can be any serde::Serialize
or serde::Deserialize
types
Examples
// Import the Common libraries
extern crate cmn;
use cmn::Constants;
use cmn::Words;
// Constants
let constants = Constants::new();
let constant = constants.constant("EULER");
assert_eq!(constant.unwrap().name, "EULER");
// Words
let words = Words::new();
let words_list = words.words_list();
assert_eq!(words_list[0], "aboard");
License
The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Re-exports
Modules
- The
constants
module contains theConstants
structure, which provides a collection of constant values that are used throughout the library. - The
macros
module contains functions for generating macros. Macros for the cmn crate. - The
words
module contains theWords
structure, which provides a collection of words that are used throughout the library.
Macros
- This macro takes any number of arguments and parses them into a Rust value.
- This macro asserts that the given condition is true. If the condition is false, the macro panics with the given message.
- This macro defines a set of constants with their corresponding values. The macros can be used to define constants in a concise and easy-to-read way.
- This macro checks if the given string contains the given substring.
- This macro checks if the given value is within the given range.
- This macro joins the given strings together with the given separator.
- This macro finds the maximum value of the given values.
- This macro finds the minimum value of the given values.
- This macro parses the given input into a Rust value.
- This macro prints the given arguments to the console.
- This macro prints the given vector of values to the console.
- This macro splits the given string into a vector of strings.
- This macro creates a new vector with the given elements.
Structs
- The
Common
structure provides a central location to store data that is commonly used throughout the library. The structure implements theSerialize
andDeserialize
traits from theserde
crate to enable serialization and deserialization of the data.
Functions
- This is the main entry point for the
Common (CMN)
library.