pub struct AprWriter { /* private fields */ }Expand description
APR format writer — delegates to AprV2Writer for ONE format.
This is a convenience wrapper around AprV2Writer that provides a simple
key-value metadata API. All output uses the canonical APR format (v2 binary
layout with header, metadata, tensor index, and aligned data sections).
Implementations§
Source§impl AprWriter
impl AprWriter
Sourcepub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
pub fn set_metadata(&mut self, key: impl Into<String>, value: Value)
Set metadata key-value pair
Sourcepub fn add_tensor_f32(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: &[f32],
)
pub fn add_tensor_f32( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )
Add tensor with f32 data (copies the slice)
Sourcepub fn add_tensor_f32_owned(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: Vec<f32>,
)
pub fn add_tensor_f32_owned( &mut self, name: impl Into<String>, shape: Vec<usize>, data: Vec<f32>, )
ALB-099: Add tensor with owned f32 data — zero-copy for large tensors.
Use this when the caller already owns a Vec
Sourcepub fn into_bytes(self) -> Result<Vec<u8>, String>
pub fn into_bytes(self) -> Result<Vec<u8>, String>
ALB-099: Consume the writer and serialize — zero-copy for owned tensor data.
Avoids the f32→bytes copy for tensors added via add_tensor_f32_owned.
§Errors
Returns error if serialization fails
Sourcepub fn write<P>(&self, path: P) -> Result<(), String>
pub fn write<P>(&self, path: P) -> Result<(), String>
Write to file atomically (F-CKPT-009).
Writes to a .tmp file, fsyncs, then renames. A crash at any point
leaves the original file intact.
§Errors
Returns error if write fails
Sourcepub fn write_into<P>(self, path: P) -> Result<(), String>
pub fn write_into<P>(self, path: P) -> Result<(), String>
ALB-105: Consuming streaming write — streams tensor data to disk
instead of serializing the entire model into a Vec
Peak RAM = metadata + tensor index + largest single tensor (not all tensors).
Same atomic write semantics as write() (F-CKPT-009): writes to a .tmp
file via AprV2StreamingWriter, fsyncs, then renames.
§Errors
Returns error if write fails
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AprWriter
impl RefUnwindSafe for AprWriter
impl Send for AprWriter
impl Sync for AprWriter
impl Unpin for AprWriter
impl UnsafeUnpin for AprWriter
impl UnwindSafe for AprWriter
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