Crates.io | stoik |
lib.rs | stoik |
version | 0.1.0 |
source | src |
created_at | 2024-02-24 14:53:44.596086 |
updated_at | 2024-02-24 14:53:44.596086 |
description | Libary to parse molecular formulas |
homepage | https://github.com/htmlcsjs/stoik |
repository | https://github.com/htmlcsjs/stoik |
max_upload_size | |
id | 1151691 |
size | 25,822 |
Stoicimetic utilities written in rust.
To see an example how this is used in the real world, look at the CLI
use stoik::formula::Molecule;
use stoik::StoikError;
let formula = "Rh2(SO4)3";
match Molecule::from_formula(formula) {
Err(e) => match e {
StoikError::InvalidToken(loc) => {
println!("{}",
loc.format_msg(formula, "Malformed formula", "Illegal token")
)
}
StoikError::NumberFirst(loc) => println!("{}",
loc.format_msg(
formula,
"Malformed formula",
"Compound groups cannot start\nwith numbers",
)
),
StoikError::UnpairedParenthesis(loc) => {
println!("{}",
loc.format_msg(formula, "Malformed formula", "Unpaired parenthesis")
)
}
StoikError::UnpairedBracket(loc) => {
println!("{}",
loc.format_msg(formula, "Malformed formula", "Unpaired bracket")
)
}
e => println!("{e}"),
},
Ok(mol) => {
println!("{formula} contains:")
//...
}
}