BurnpackWriter

Struct BurnpackWriter 

Source
pub struct BurnpackWriter { /* private fields */ }
Expand description

Writer for creating Burnpack files

Implementations§

Source§

impl BurnpackWriter

Source

pub fn new(snapshots: Vec<TensorSnapshot>) -> Self

Create a new writer

Source

pub fn with_metadata(self, key: &str, value: &str) -> Self

Builder pattern: add metadata and return self

Source

pub fn size(&self) -> Result<usize, BurnpackError>

Calculate the total size needed for the burnpack data

This is useful when you want to pre-allocate a buffer for write_into(). The size includes padding bytes for both metadata alignment and tensor alignment.

Source

pub fn write_into(&self, buffer: &mut [u8]) -> Result<(), BurnpackError>

Write burnpack data into a caller-provided buffer

The buffer must be large enough to hold all data. Use size() to determine the required buffer size. If the buffer is too small, this will return an error.

This allows the caller to control buffer allocation, enabling optimizations like:

  • Buffer reuse across multiple writes
  • Custom allocators
  • Pinned memory for GPU transfers
§Arguments
  • buffer - Mutable slice to write data into. Must be at least size() bytes.
Source

pub fn to_bytes(&self) -> Result<Bytes, BurnpackError>

Write to a byte buffer (convenience method)

This allocates a buffer internally and writes the burnpack data. For more control over buffer allocation, use size() + write_into().

Source

pub fn write_to_file<P: AsRef<Path>>( &self, path: P, ) -> Result<(), BurnpackError>

Write directly to a file (more memory efficient for large models)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V