stoik

Crates.iostoik
lib.rsstoik
version0.1.0
sourcesrc
created_at2024-02-24 14:53:44.596086
updated_at2024-02-24 14:53:44.596086
descriptionLibary to parse molecular formulas
homepagehttps://github.com/htmlcsjs/stoik
repositoryhttps://github.com/htmlcsjs/stoik
max_upload_size
id1151691
size25,822
(htmlcsjs)

documentation

README

Stoik

Stoicimetic utilities written in rust.

To see an example how this is used in the real world, look at the CLI

Example use

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:")
        //...
    }
}
Commit count: 0

cargo fmt