elements_rs

Crates.ioelements_rs
lib.rselements_rs
version0.1.2
created_at2025-11-05 12:32:16.95514+00
updated_at2026-01-25 07:13:11.519409+00
descriptionA comprehensive library for chemical elements and their isotopes with rich metadata
homepage
repositoryhttps://github.com/earth-metabolome-initiative/elements-rs
max_upload_size
id1917927
size1,779,848
Luca Cappelletti (LucaCappelletti94)

documentation

README

Elements

CI License: MIT Codecov Crates.io Docs.rs

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.

The crate is no_std, and optionally supports serde for serialization/deserialization.

Usage

Add this to your Cargo.toml:

[dependencies]
elements_rs = "0.1"

Basic Example

use elements_rs::{Element, BondsNumber, ValenceElectrons};

// Get an element
let carbon = Element::C;

// Access properties
println!("Name: {}", carbon.name());
println!("Atomic weight: {}", carbon.standard_atomic_weight());
println!("Valence electrons: {}", carbon.valence_electrons());

// Check oxidation states
assert!(carbon.is_valid_oxidation_state(4));
assert!(carbon.is_valid_oxidation_state(-4));

// Get bond information
let (min_bonds, max_bonds) = carbon.number_of_bonds();
assert_eq!((min_bonds, max_bonds), (4, 4));

Working with Isotopes

use elements_rs::isotopes::{CarbonIsotope, Isotope, MassNumber, RelativeAtomicMass};

// Get a specific isotope
let carbon_12 = CarbonIsotope::C12;
println!("Mass number: {}", carbon_12.mass_number());
println!("Relative atomic mass: {}", carbon_12.relative_atomic_mass());

// Work with the generic Isotope enum
let isotope = Isotope::C(carbon_12);

Parsing from Strings

use elements_rs::Element;
use std::str::FromStr;

// Parse element symbols
let oxygen = Element::from_str("O").unwrap();
let nitrogen = Element::from_str("N").unwrap();

Feature Flags

  • serde (default): Enables Serialize and Deserialize implementations for Element and Isotope types

License

This project is licensed under the same terms as the parent EMI monorepo.

Commit count: 39

cargo fmt