Skip to main content

Buffer

Struct Buffer 

Source
pub struct Buffer { /* private fields */ }

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Examples found in repository?
examples/basic.rs (line 4)
3fn main() {
4    let mut buffer = Buffer::new();
5    let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6    let mut fields = [serialize_scalar(42_i32), name];
7    serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9    let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10    let id = view.scalar::<i32>(0).expect("id field");
11    let name = view
12        .string(1)
13        .and_then(|value| value.as_str())
14        .expect("UTF-8 name field");
15
16    println!("id={id}, name={name}");
17}
Source

pub fn with_capacity_words(words: usize) -> Self

Source

pub fn clear(&mut self)

Source

pub fn allocated_words(&self) -> usize

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn view(&self) -> &[u32]

Examples found in repository?
examples/basic.rs (line 9)
3fn main() {
4    let mut buffer = Buffer::new();
5    let name = serialize_str("Ada", &mut buffer).expect("name is encodable");
6    let mut fields = [serialize_scalar(42_i32), name];
7    serialize_message(&mut fields, &mut buffer).expect("message is encodable");
8
9    let view = MessageView::new(buffer.view()).expect("valid ProtoCache message");
10    let id = view.scalar::<i32>(0).expect("id field");
11    let name = view
12        .string(1)
13        .and_then(|value| value.as_str())
14        .expect("UTF-8 name field");
15
16    println!("id={id}, name={name}");
17}
Source

pub fn head(&self) -> &[u32]

Source

pub fn head_mut(&mut self) -> &mut [u32]

Source

pub fn at_from_end(&self, words: usize) -> Option<&[u32]>

Source

pub fn at_from_end_mut(&mut self, words: usize) -> Option<&mut [u32]>

Source

pub fn reserve_words(&mut self, words: usize)

Source

pub fn expand(&mut self, delta: usize) -> &mut [u32]

Source

pub fn shrink(&mut self, delta: usize)

Source

pub fn put(&mut self, value: u32)

Source

pub fn put_words(&mut self, words: &[u32])

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Buffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Buffer

Source§

fn default() -> Buffer

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.