pub struct ByteBuilder<T> { /* private fields */ }
Expand description
A dynamically created buffer for T
Implementations§
source§impl<T> ByteBuilder<T>
impl<T> ByteBuilder<T>
sourcepub fn new_fixed(size: NonZeroUsize) -> Self
pub fn new_fixed(size: NonZeroUsize) -> Self
Create a builder of fixed size
sourcepub fn bytes(self, v: &[u8]) -> Self
pub fn bytes(self, v: &[u8]) -> Self
Append bytes in the builder
Examples found in repository?
src/typed_bytes/builder.rs (line 114)
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
pub fn u16(self, v: u16) -> Self {
self.bytes(&v.to_be_bytes())
}
/// Append an u32 in the builder
pub fn u32(self, v: u32) -> Self {
self.bytes(&v.to_be_bytes())
}
/// Append an u64 in the builder
pub fn u64(self, v: u64) -> Self {
self.bytes(&v.to_be_bytes())
}
/// Append an u128 in the builder
pub fn u128(self, v: u128) -> Self {
self.bytes(&v.to_be_bytes())
}
sourcepub fn fold<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator,
F: FnMut(Self, I::Item) -> Self,
pub fn fold<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator,
F: FnMut(Self, I::Item) -> Self,
fold over an iterator
sourcepub fn iter8<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator + ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
pub fn iter8<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator + ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
write an iterator of maximum 256 items using the closure F
note that the buffer contains a byte to represent the size of the list
sourcepub fn iter16<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator + ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
pub fn iter16<F, I>(self, l: I, f: F) -> Selfwhere
I: Iterator + ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
write an iterator of maximum 2^16 items using the closure F
note that the buffer contains 2 bytes to represent the size of the list
pub fn sub<F, U>(self, f: F) -> Selfwhere
F: Fn(ByteBuilder<U>) -> ByteBuilder<U>,
sourcepub fn finalize_as_vec(self) -> Vec<u8>
pub fn finalize_as_vec(self) -> Vec<u8>
Finalize the buffer and return a fixed ByteArray of T
Trait Implementations§
source§impl<T: Clone> Clone for ByteBuilder<T>
impl<T: Clone> Clone for ByteBuilder<T>
source§fn clone(&self) -> ByteBuilder<T>
fn clone(&self) -> ByteBuilder<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more