[][src]Struct body_image::BodySink

pub struct BodySink { /* fields omitted */ }

A logical buffer of bytes, which may or may not be RAM resident, in the process of being written. This is the write-side corollary to BodyImage.

A BodySink is always in one of the following states, as a buffering strategy:

Ram : A vector of zero, one, or many discontinuous (AKA scattered) byte buffers in Random Access Memory. This state is also used to represent an empty body (without allocation).

FsWrite : Body being written to a (temporary) file.

Methods

impl BodySink[src]

pub fn empty() -> BodySink[src]

Create new empty instance, which does not pre-allocate. The state is Ram with a zero-capacity vector.

pub fn with_ram(size_estimate: u64) -> BodySink[src]

Create a new Ram instance by pre-allocating a vector of buffers based on the given size estimate in bytes, assuming 8 KiB buffers. With a size_estimate of 0, this is the same as empty.

pub fn with_ram_buffers(capacity: usize) -> BodySink[src]

Create a new Ram instance by pre-allocating a vector of the specified capacity.

pub fn with_fs<P>(dir: P) -> Result<BodySink, BodyError> where
    P: AsRef<Path>, 
[src]

Create a new instance in state FsWrite, using a new temporary file created in dir.

pub fn is_ram(&self) -> bool[src]

Return true if in state Ram.

pub fn is_empty(&self) -> bool[src]

Return true if body is empty.

pub fn len(&self) -> u64[src]

Return the current length of body in bytes.

pub fn save<T>(&mut self, buf: T) -> Result<(), BodyError> where
    T: Into<Bytes>, 
[src]

Save bytes by appending to Ram or writing to FsWrite file. When in state Ram this may be more efficient than write_all if Into<Bytes> doesn't copy.

pub fn write_all<T>(&mut self, buf: T) -> Result<(), BodyError> where
    T: AsRef<[u8]>, 
[src]

Write all bytes to self. When in state FsWrite this is copy free and more optimal than save.

pub fn write_back<P>(&mut self, dir: P) -> Result<&mut Self, BodyError> where
    P: AsRef<Path>, 
[src]

If Ram, convert to FsWrite by writing all bytes in RAM to a temporary file, created in dir. No-op if already FsWrite. Buffers are eagerly dropped as they are written. As a consequence, if any error result is returned (e.g. opening or writing to the file), self will be empty and in the Ram state. There is no practical recovery for the original body.

pub fn prepare(self) -> Result<BodyImage, BodyError>[src]

Consumes self, converts and returns as BodyImage ready for read.

Trait Implementations

impl Default for BodySink[src]

impl Debug for BodySink[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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