Struct puff_rs::types::bytes_builder::BytesBuilder
source · pub struct BytesBuilder(_);Expand description
Fast Byte Buffer
Puff’s BytesBuilder type uses std::vec::Vec under the hood. Vecs are not
sharable structures and so need to be wrapped in an Arc to be shared between threads and cheaply copied.
You should use a BytesBuilder and convert it into Bytes when you are done writing to it.
Examples
use puff_rs::types::BytesBuilder;
let mut builder = BytesBuilder::new();
builder.put("hello_world");
let bytes = builder.into_bytes();Implementations
sourceimpl BytesBuilder
impl BytesBuilder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty BytesBuilder.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use puff_rs::types::{Text, BytesBuilder};
let mut builder = BytesBuilder::new();sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty BytesBuilder with the specified capacity.
The buffer will be able to hold at least capacity elements without
reallocating. If capacity is 0, the hash map will not allocate.
Examples
use puff_rs::types::BytesBuilder;
let mut builder = BytesBuilder::with_capacity(10);sourcepub fn put<T: Into<Bytes>>(&mut self, slice: T)
pub fn put<T: Into<Bytes>>(&mut self, slice: T)
Puts some bytes into the builder.
Examples
use puff_rs::types::BytesBuilder;
let mut builder = BytesBuilder::new();
builder.put("Hi");sourcepub fn put_slice(&mut self, slice: &[u8])
pub fn put_slice(&mut self, slice: &[u8])
Puts a slice into the builder.
Examples
use puff_rs::types::BytesBuilder;
let mut builder = BytesBuilder::new();
builder.put_slice("Hi".as_bytes());sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Converts BytesBuilder into Bytes.
Auto Trait Implementations
impl RefUnwindSafe for BytesBuilder
impl Send for BytesBuilder
impl Sync for BytesBuilder
impl Unpin for BytesBuilder
impl UnwindSafe for BytesBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more