pub struct MmapWriter { /* private fields */ }Expand description
Memory-mapped MRC writer (requires mmap feature).
Memory-mapped MRC file writer.
Writes data directly into a memory-mapped region, letting the OS handle
paging and flushing. This is efficient for large files and random-access
modifications, but requires the mmap feature.
§Example
use mrc::{create, VoxelBlock};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut writer = create("output.mrc")
.shape([512, 512, 256])
.mode::<f32>()
.finish_mmap()?;
writer.write_block(&VoxelBlock::new(
[0, 0, 0], [512, 512, 1],
vec![0.0f32; 512 * 512],
)?)?;
Ok(())
}For most use cases, prefer creating via WriterBuilder::finish_mmap.
Implementations§
Source§impl MmapWriter
impl MmapWriter
Sourcepub fn shape(&self) -> VolumeShape
pub fn shape(&self) -> VolumeShape
Volume dimensions for this writer.
Sourcepub fn mode(&self) -> Mode
pub fn mode(&self) -> Mode
Voxel data mode for this writer.
Falls back to Mode::Float32 if the header mode value is not recognised.
Sourcepub fn header(&self) -> &Header
pub fn header(&self) -> &Header
Reference to the current header.
Modify header fields before calling finalize to
change what gets written to disk.
Sourcepub fn write_u8_block(&mut self, block: &VoxelBlock<u8>) -> Result<(), Error>
pub fn write_u8_block(&mut self, block: &VoxelBlock<u8>) -> Result<(), Error>
Write a block of u8 data by automatically widening to u16 (Mode 6).
The file must have been created with Mode::Uint16. Each u8 voxel
is widened to u16 before writing, matching Python mrcfile’s
auto-conversion behaviour for np.uint8 data.
§Errors
Returns Error::ModeMismatch if the file mode is not Uint16.
Sourcepub fn write_block<T: Voxel>(
&mut self,
block: &VoxelBlock<T>,
) -> Result<(), Error>
pub fn write_block<T: Voxel>( &mut self, block: &VoxelBlock<T>, ) -> Result<(), Error>
Write a block of voxels to the memory-mapped file.
The type T must match the file’s voxel mode exactly.
Supports arbitrary sub-blocks by scattering row-by-row when necessary.
Sourcepub fn write_block_parallel<T: Voxel>(
&mut self,
block: &VoxelBlock<T>,
) -> Result<(), Error>
pub fn write_block_parallel<T: Voxel>( &mut self, block: &VoxelBlock<T>, ) -> Result<(), Error>
Write a block with parallel encoding to memory-mapped region.
For non-contiguous blocks (sub-XY slabs), this falls back to the serial
write_block implementation.
Sourcepub fn write_f16_from_f32(
&mut self,
block: &VoxelBlock<f32>,
) -> Result<(), Error>
pub fn write_f16_from_f32( &mut self, block: &VoxelBlock<f32>, ) -> Result<(), Error>
Write an f32 block to a Float16 file.
Sourcepub fn update_header_stats(&mut self) -> Result<(), Error>
pub fn update_header_stats(&mut self) -> Result<(), Error>
Scan the written data block and update header statistics.
Unlike Writer::update_header_stats, this does not need to read from
disk because the data is already accessible via the memory map.
Source§impl MmapWriter
impl MmapWriter
Sourcepub fn finalize(&mut self) -> Result<(), Error>
pub fn finalize(&mut self) -> Result<(), Error>
Finalize the memory-mapped MRC file by writing the header.
This updates the first 1024 bytes of the memory map with the current
header and flushes the mapping to disk. Must be called after all
write_block calls.
§Errors
Returns Error::Io if the flush fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MmapWriter
impl RefUnwindSafe for MmapWriter
impl Send for MmapWriter
impl Sync for MmapWriter
impl Unpin for MmapWriter
impl UnsafeUnpin for MmapWriter
impl UnwindSafe for MmapWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more