v_escape

Trait Buffer

Source
pub trait Buffer {
    type Freeze;

    // Required methods
    fn with_capacity(capacity: usize) -> Self
       where Self: Sized;
    fn is_empty(&self) -> bool;
    fn len(&self) -> usize;
    unsafe fn extend_from_slice(&mut self, src: &[u8]);
    fn reserve(&mut self, additional: usize);
    fn freeze(self) -> Self::Freeze;
    unsafe fn advance(&mut self, cnt: usize);
    unsafe fn buf_ptr(&mut self) -> *mut u8;

    // Provided method
    fn extend(&mut self, src: &str) { ... }
}
Expand description

Minimal Buffer trait with utf-8 safety

Required Associated Types§

Source

type Freeze

Into immutable type

Required Methods§

Source

fn with_capacity(capacity: usize) -> Self
where Self: Sized,

Returns new Buffer with capacity

Source

fn is_empty(&self) -> bool

Returns true if the Buffer has a length of 0.

Source

fn len(&self) -> usize

Source

unsafe fn extend_from_slice(&mut self, src: &[u8])

Appends given bytes to this Buffer.

§Safety

Broke utf-8 safety

§Panics

Can panic if current length plus src length overflows usize

Source

fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more bytes to be inserted into the given Buffer.

§Panics

Can panic if current capacity plus additional overflows usize

Source

fn freeze(self) -> Self::Freeze

Converts self into a Freeze type

Source

unsafe fn advance(&mut self, cnt: usize)

Advance the internal cursor of the Buffer

§Safety

Can’t advance more than capacity of the Buffer

§Panics

Can panic if length plus cnt is bigger than capacity

Source

unsafe fn buf_ptr(&mut self) -> *mut u8

Return unsafe ptr to current Buffer position

§Safety

If buffer is full, can return invalid pointer

Provided Methods§

Source

fn extend(&mut self, src: &str)

Appends given str to this Buffer.

§Panics

Can panic if current length plus src length overflows usize

Implementations on Foreign Types§

Source§

impl Buffer for String

Source§

type Freeze = String

Source§

fn with_capacity(capacity: usize) -> String
where String: Sized,

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

unsafe fn extend_from_slice(&mut self, src: &[u8])

Source§

fn reserve(&mut self, additional: usize)

Source§

fn freeze(self) -> <String as Buffer>::Freeze

Source§

unsafe fn advance(&mut self, cnt: usize)

Source§

unsafe fn buf_ptr(&mut self) -> *mut u8

Source§

impl Buffer for Vec<u8>

Source§

type Freeze = Vec<u8>

Source§

fn with_capacity(capacity: usize) -> Vec<u8>
where Vec<u8>: Sized,

Source§

fn is_empty(&self) -> bool

Source§

fn len(&self) -> usize

Source§

unsafe fn extend_from_slice(&mut self, src: &[u8])

Source§

fn reserve(&mut self, additional: usize)

Source§

fn freeze(self) -> <Vec<u8> as Buffer>::Freeze

Source§

unsafe fn advance(&mut self, cnt: usize)

Source§

unsafe fn buf_ptr(&mut self) -> *mut u8

Implementors§