Trait zstd_safe::WriteBuf

source ·
pub unsafe trait WriteBuf {
    // Required methods
    fn as_slice(&self) -> &[u8] ;
    fn capacity(&self) -> usize;
    fn as_mut_ptr(&mut self) -> *mut u8;
    unsafe fn filled_until(&mut self, n: usize);

    // Provided method
    unsafe fn write_from<F>(&mut self, f: F) -> SafeResult
       where F: FnOnce(*mut c_void, usize) -> SafeResult { ... }
}
Expand description

Describe a resizeable bytes container like Vec<u8>.

Represents a contiguous segment of memory, a prefix of which is initialized.

It allows starting from an uninitializes chunk of memory and writing to it.

The main implementors are:

  • Vec<u8> and similar structures. These can start empty with a non-zero capacity, and they will be resized to cover the data written. Any existing data will be overwritten.
  • [u8] and [u8; N]. These must start already-initialized, and will not be resized. It will be up to the caller to only use the part that was written.
  • std::io::Cursor<T: WriteBuf>. This will ignore data before the cursor’s position, and append data after that.

Required Methods§

source

fn as_slice(&self) -> &[u8]

Returns the valid data part of this container. Should only cover initialized data.

source

fn capacity(&self) -> usize

Returns the full capacity of this container. May include uninitialized data.

source

fn as_mut_ptr(&mut self) -> *mut u8

Returns a pointer to the start of the data.

source

unsafe fn filled_until(&mut self, n: usize)

Indicates that the first n bytes of the container have been written.

Safety: this should only be called if the n first bytes of this buffer have actually been initialized.

Provided Methods§

source

unsafe fn write_from<F>(&mut self, f: F) -> SafeResultwhere F: FnOnce(*mut c_void, usize) -> SafeResult,

Call the given closure using the pointer and capacity from self.

Assumes the given function returns a parseable code, which if valid, represents how many bytes were written to self.

The given closure must treat its first argument as pointing to potentially uninitialized memory, and should not read from it.

In addition, it must have written at least n bytes contiguously from this pointer, where n is the returned value.

Implementations on Foreign Types§

source§

impl WriteBuf for Vec<u8>

Available on crate feature std only.
source§

fn as_slice(&self) -> &[u8]

source§

fn capacity(&self) -> usize

source§

fn as_mut_ptr(&mut self) -> *mut u8

source§

unsafe fn filled_until(&mut self, n: usize)

source§

impl<T> WriteBuf for Cursor<T>where T: WriteBuf,

Available on crate feature std only.
source§

fn as_slice(&self) -> &[u8]

source§

fn capacity(&self) -> usize

source§

fn as_mut_ptr(&mut self) -> *mut u8

source§

unsafe fn filled_until(&mut self, n: usize)

source§

impl<'a> WriteBuf for &'a mut Vec<u8>

Available on crate feature std only.
source§

fn as_slice(&self) -> &[u8]

source§

fn capacity(&self) -> usize

source§

fn as_mut_ptr(&mut self) -> *mut u8

source§

unsafe fn filled_until(&mut self, n: usize)

source§

impl WriteBuf for [u8]

source§

fn as_slice(&self) -> &[u8]

source§

fn capacity(&self) -> usize

source§

fn as_mut_ptr(&mut self) -> *mut u8

source§

unsafe fn filled_until(&mut self, _n: usize)

source§

impl<const N: usize> WriteBuf for [u8; N]

Available on crate feature arrays only.
source§

fn as_slice(&self) -> &[u8]

source§

fn capacity(&self) -> usize

source§

fn as_mut_ptr(&mut self) -> *mut u8

source§

unsafe fn filled_until(&mut self, _n: usize)

Implementors§