Struct typed_bytes::builder::ByteBuilder
source · pub struct ByteBuilder<T> {
buffer: Vec<u8>,
phantom: PhantomData<T>,
expected: Option<NonZeroUsize>,
}
Expand description
A dynamically created buffer for T
Fields§
§buffer: Vec<u8>
§phantom: PhantomData<T>
§expected: Option<NonZeroUsize>
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 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: IntoIterator,
I::IntoIter: ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
pub fn iter8<F, I>(self, l: I, f: F) -> Selfwhere I: IntoIterator, I::IntoIter: ExactSizeIterator, F: FnMut(Self, I::Item) -> Self,
Write an iterator of maximum 255 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: IntoIterator,
I::IntoIter: ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
pub fn iter16<F, I>(self, l: I, f: F) -> Selfwhere I: IntoIterator, I::IntoIter: ExactSizeIterator, F: FnMut(Self, I::Item) -> Self,
Write an iterator of maximum 2^16 - 1 items using the closure f
.
Note that the buffer contains 2 bytes to represent the size of the list.
sourcepub fn iter32<F, I>(self, l: I, f: F) -> Selfwhere
I: IntoIterator,
I::IntoIter: ExactSizeIterator,
F: FnMut(Self, I::Item) -> Self,
pub fn iter32<F, I>(self, l: I, f: F) -> Selfwhere I: IntoIterator, I::IntoIter: ExactSizeIterator, F: FnMut(Self, I::Item) -> Self,
Write an iterator of maximum 2^32 - 1 items using the closure f
.
Note that the buffer contains 4 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 option<F, V>(self, value: Option<V>, f: F) -> Selfwhere
F: FnOnce(Self, V) -> Self,
pub fn option<F, V>(self, value: Option<V>, f: F) -> Selfwhere F: FnOnce(Self, V) -> Self,
Call ‘f’ on bytebuilder and the value if the value is present, then return the bytebuilder, otherwise just return the bytebuilder
sourcepub fn option_or_else<F, G, V>(self, value: Option<V>, default: G, f: F) -> Selfwhere
F: FnOnce(Self, V) -> Self,
G: FnOnce(Self) -> Self,
pub fn option_or_else<F, G, V>(self, value: Option<V>, default: G, f: F) -> Selfwhere F: FnOnce(Self, V) -> Self, G: FnOnce(Self) -> Self,
Run the first closure if the value is not present, or the second closure with the present parameter.
this is loosely based on Option::map_or_else
The following call:
byte_builder.option_or_else(value, none_call, some_call);
equivalent to the construction:
if let Some(value) = value {
some_call(byte_builder, value)
} else {
none_call(byte_builder)
}
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>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more