imodfile 0.2.2

A pure-Rust IMOD model file decoder/encoder — binary & ASCII, with Python bindings
Documentation
#![doc = include_str!("../README.md")]

pub mod ascii;
pub mod binary;
pub mod chunk_ids;
pub mod error;
pub mod model;
pub mod store;

/// Python bindings (requires feature `python`).
#[cfg(feature = "python")]
pub mod python;

pub use ascii::{read_ascii, write_ascii};
pub use binary::{read_binary, write_binary};
pub use error::{ImodError, ImodResult};

// ── Data model ──
pub use model::{
    IclipPlanes, Icont, Iindex, Imesh, ImeshParams, Imod, Iobj,
    IobjPointsIter, ImodPointsIter, Iplane, Ipoint, IrefImage,
    Istore, IstoreItem, Iview, Ilabel, IlabelItem, SlicerAngles,
};

// ── Model flags (IMODF_*) ──
pub use model::{
    IMODF_FLIPYZ, IMODF_HAS_MESH_THICK, IMODF_MAT1_IS_BYTES,
    IMODF_MULTIPLE_CLIP, IMODF_NEW_TO_3DMOD, IMODF_OTRANS_ORIGIN,
    IMODF_ROT90X, IMODF_TILTOK, IMODF_Z_FROM_MINUSPT5,
};

// ── Object flags (IMOD_OBJFLAG_*) ──
pub use model::{
    IMOD_OBJFLAG_ANTI_ALIAS, IMOD_OBJFLAG_DRAW_LABEL,
    IMOD_OBJFLAG_FCOLOR, IMOD_OBJFLAG_FCOLOR_PNT,
    IMOD_OBJFLAG_FILL, IMOD_OBJFLAG_MCOLOR, IMOD_OBJFLAG_MESH,
    IMOD_OBJFLAG_NOLINE, IMOD_OBJFLAG_OFF, IMOD_OBJFLAG_OPEN,
    IMOD_OBJFLAG_OUT, IMOD_OBJFLAG_PNT_ON_SEC, IMOD_OBJFLAG_SCAT,
    IMOD_OBJFLAG_SCALE_WDTH, IMOD_OBJFLAG_TIME, IMOD_OBJFLAG_TWO_SIDE,
    IMOD_OBJFLAG_USE_VALUE,
};

/// Read an IMOD model from a file path, auto-detecting binary vs ASCII.
///
/// Shortcut for [`Imod::load`].
///
/// For in-memory round-trips use [`read_binary`] / [`write_binary`] directly:
///
/// ```rust
/// use std::io::Cursor;
/// use imodfile::{Imod, write_binary, read_binary};
/// let model = Imod::default();
/// let mut buf = Vec::new();
/// write_binary(&mut Cursor::new(&mut buf), &model).unwrap();
/// let model2 = read_binary(&mut Cursor::new(&buf)).unwrap();
/// assert_eq!(model.name, model2.name);
/// ```
///
/// ```no_run
/// let model = imodfile::read("model.mod").unwrap();
/// ```
pub fn read(path: &str) -> ImodResult<Imod> {
    Imod::load(path)
}

/// Write an IMOD model to a file path.  Uses binary format unless the path
/// ends with `.txt` or `.ascii` (then ASCII).
///
/// Shortcut for [`Imod::save`].
///
/// For in-memory round-trips use [`write_binary`] / [`read_binary`] directly:
///
/// ```rust
/// use std::io::Cursor;
/// use imodfile::{Imod, write_binary, read_binary};
/// let mut model = Imod::default();
/// model.name = "test".into();
/// let mut buf = Vec::new();
/// write_binary(&mut Cursor::new(&mut buf), &model).unwrap();
/// let model2 = read_binary(&mut Cursor::new(&buf)).unwrap();
/// assert_eq!(model.name, model2.name);
/// ```
///
/// ```no_run
/// let model = imodfile::read("model.mod").unwrap();
/// imodfile::write("output.mod", &model).unwrap();
/// ```
pub fn write(path: &str, model: &Imod) -> ImodResult<()> {
    model.save(path)
}