Skip to main content

mrc/
lib.rs

1//! MRC file format library for cryo-EM and tomography
2//!
3//! Provides iterator-centric reading and voxel-block writing with SIMD acceleration.
4//!
5//! # Architecture
6//!
7//! This crate implements a unified encoding/decoding pipeline:
8//! ```text
9//! Raw Bytes → Endian Normalization → Typed Values → Type Conversion
10//! ```
11//!
12//! With zero-copy fast paths whenever possible.
13
14#![no_std]
15#![cfg_attr(feature = "f16", feature(f16))]
16
17#[cfg(feature = "std")]
18extern crate alloc;
19
20#[cfg(feature = "std")]
21extern crate std;
22
23mod error;
24mod header;
25mod iter;
26mod mode;
27mod reader;
28mod writer;
29
30#[cfg(feature = "mmap")]
31mod mmap_reader;
32
33mod engine;
34
35// Re-export core types
36pub use engine::block::{VolumeShape, VoxelBlock};
37pub use engine::endian::FileEndian;
38
39// Re-export codec trait for advanced users who need custom voxel types
40pub use engine::codec::EndianCodec;
41
42// Re-export conversion trait and pipeline types for type conversion
43pub use engine::convert::Convert;
44pub use engine::pipeline::{ConversionPath, get_conversion_path, is_zero_copy};
45
46// Re-export SIMD batch conversions when available
47#[cfg(feature = "simd")]
48pub use engine::convert::{convert_i8_slice_to_f32, convert_i16_slice_to_f32, convert_u16_slice_to_f32, convert_u8_slice_to_f32, try_simd_convert};
49
50// Re-export f16 batch conversions when f16 feature is enabled
51#[cfg(feature = "f16")]
52pub use engine::convert::{convert_f16_slice_to_f32, convert_f32_slice_to_f16};
53
54// Re-export SliceAccess trait for writers
55pub use engine::block::SliceAccess;
56
57pub use error::Error;
58pub use header::{ExtHeader, ExtHeaderMut, Header};
59pub use mode::{Float32Complex, Int16Complex, Mode, Packed4Bit, Voxel};
60pub use reader::Reader;
61pub use writer::{Writer, WriterBuilder};
62
63// Re-export conversion-enabled iterators
64pub use iter::{SliceIterConverted, SlabIterConverted};
65
66#[cfg(feature = "mmap")]
67pub use writer::MmapWriter;
68
69#[cfg(feature = "mmap")]
70pub use mmap_reader::MmapReader;
71
72/// Open an MRC file for reading
73#[cfg(feature = "std")]
74pub fn open(path: &str) -> Result<Reader, Error> {
75    Reader::open(path)
76}
77
78/// Create a new MRC file for writing
79#[cfg(feature = "std")]
80pub fn create(path: &str) -> WriterBuilder {
81    WriterBuilder::new(path)
82}