pub struct Buffer { /* private fields */ }Expand description
Reusable reverse-growing word buffer used by ProtoCache encoders.
Encoders prepend data, so existing segment positions remain stable as the
allocation grows. Call Self::clear to reuse allocated capacity.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty buffer without an allocation.
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}Sourcepub fn with_capacity_words(words: usize) -> Self
pub fn with_capacity_words(words: usize) -> Self
Creates an empty buffer with capacity for at least words words.
pub fn allocated_words(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn view(&self) -> &[u32]
pub fn view(&self) -> &[u32]
Returns the active encoded words.
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}pub fn head(&self) -> &[u32]
pub fn head_mut(&mut self) -> &mut [u32]
pub fn at_from_end(&self, words: usize) -> Option<&[u32]>
pub fn at_from_end_mut(&mut self, words: usize) -> Option<&mut [u32]>
pub fn reserve_words(&mut self, words: usize)
Sourcepub fn expand(&mut self, delta: usize) -> &mut [u32]
pub fn expand(&mut self, delta: usize) -> &mut [u32]
Prepends delta zero-initialized words and returns them for writing.
pub fn put(&mut self, value: u32)
pub fn put_words(&mut self, words: &[u32])
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnsafeUnpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more