castep-cell-io 0.1.3

A crate helping to parse, edit and save `castep` input file format `.cell`
Documentation
use winnow::{combinator::rest, PResult, Parser};

use crate::{
    data::LengthUnit,
    keywords::{DocumentSections, KeywordType},
    CellParseError,
};

pub(crate) mod ionic_positions;
pub(crate) mod lattice;

pub fn any_block<'s>(input: &mut &'s str) -> PResult<DocumentSections<'s>> {
    rest.map(|s: &str| DocumentSections::Misc(KeywordType::Block(s)))
        .parse_next(input)
}

fn length_unit(input: &str) -> Result<LengthUnit, CellParseError> {
    match input {
        "bohr" => Ok(LengthUnit::Bohr),
        "a0" => Ok(LengthUnit::Bohr),
        "m" => Ok(LengthUnit::Meter),
        "cm" => Ok(LengthUnit::Centimeter),
        "nm" => Ok(LengthUnit::Nanometer),
        "ang" => Ok(LengthUnit::Ang),
        _ => Err(CellParseError::Invalid),
    }
}