use crate::document::Document;
use crate::lower::lower;
use crate::parser::parse;
use molframe_core::io::{Format, InputBuffer, ReadOptions, ReadResult, Reader};
#[derive(Clone, Copy, Debug, Default)]
pub struct CifReader;
impl Reader for CifReader {
const FORMAT: Format = Format::Mmcif;
fn read(input: &InputBuffer, options: &ReadOptions) -> ReadResult {
read(input, options)
}
}
pub fn read(input: &InputBuffer, options: &ReadOptions) -> ReadResult {
super::direct::read(input, options)
}
#[doc(hidden)]
pub fn read_with_metadata(
input: &InputBuffer,
options: &ReadOptions,
keep_category: fn(&str) -> bool,
) -> Result<
(
Document,
molframe_core::Structure,
Vec<molframe_core::Diagnostic>,
),
Vec<molframe_core::Diagnostic>,
> {
super::direct::read_with_metadata(input, options, keep_category)
}
#[doc(hidden)]
pub type ProjectedReadResult<T> = Result<
(
Document,
molframe_core::Structure,
T,
Vec<molframe_core::Diagnostic>,
),
Vec<molframe_core::Diagnostic>,
>;
#[doc(hidden)]
pub fn read_with_projection<S>(
input: &InputBuffer,
options: &ReadOptions,
keep_category: fn(&str) -> bool,
projection: S,
) -> ProjectedReadResult<S::Output>
where
S: crate::CifEventSink,
{
super::direct::read_with_projection(input, options, keep_category, projection)
}
pub fn read_with_document(
input: &InputBuffer,
options: &ReadOptions,
) -> Result<
(
Document,
molframe_core::Structure,
Vec<molframe_core::Diagnostic>,
),
Vec<molframe_core::Diagnostic>,
> {
let (document, mut findings) = parse(input)?;
let (structure, interpretation) = lower(&document, options)?;
findings.extend(interpretation);
options
.finish(structure, findings)
.map(|(structure, findings)| (document, structure, findings))
}
#[cfg(test)]
#[path = "structure_tests.rs"]
mod tests;