Elements
A comprehensive Rust crate providing type-safe enumerations and rich metadata for all chemical elements of the periodic table and their isotopes. The crate includes all 118 elements from Hydrogen to Oganesson with detailed information for each isotope including mass numbers, relative atomic masses, isotopic composition, and identification of the most abundant isotope. Chemical properties are fully supported: standard atomic weights, oxidation states with validation, valence electrons, bond numbers, electron configurations with atomic orbitals, and principal quantum numbers. Optional features provide database integration through Diesel (PostgreSQL and SQLite), PostgreSQL extension support via PGRX, and serialization through serde.
Usage
Add this to your Cargo.toml:
[]
= "0.1"
Basic Example
use ;
// Get an element
let carbon = C;
// Access properties
println!;
println!;
println!;
// Check oxidation states
assert!;
assert!;
// Get bond information
let = carbon.number_of_bonds;
assert_eq!;
Working with Isotopes
use ;
// Get a specific isotope
let carbon_12 = C12;
println!;
println!;
// Work with the generic Isotope enum
let isotope = C;
Parsing from Strings
use Element;
use FromStr;
// Parse element symbols
let oxygen = from_str.unwrap;
let nitrogen = from_str.unwrap;
Feature Flags
serde(default): EnablesSerializeandDeserializeimplementations forElementandIsotopetypesdiesel: Adds Diesel ORM trait implementations for database queriessqlite: Enables SQLite-specific type mappings (requiresdiesel)postgres: Enables PostgreSQL-specific type mappings (requiresdiesel)diesel_pgrx: Integrates Diesel with PGRX for PostgreSQL extension development (requiresdiesel)pgrx: Enables PostgreSQL extension API through PGRXpg13,pg14,pg15,pg16,pg17: Select specific PostgreSQL version (requirespgrx, mutually exclusive)
Compiling the PGRX Extension
After cloning the repository, you can compile the PGRX extension in the ./extension directory by running:
USER_ID= GROUP_ID=
Note: The USER_ID and GROUP_ID environment variables ensure proper file permissions when mounting volumes, avoiding root-owned files on the host system.
License
This project is licensed under the same terms as the parent EMI monorepo.