pub struct FuncCodeWriter<E: Endianness, CW: CodesWrite<E> + ?Sized>(/* private fields */);
Expand description
A newtype containing a function pointer dispatching the write method for a code.
This is a more efficient way to pass a StaticCodeWrite
to a method, as
a FuncCodeWriter
does not need to do a runtime test to dispatch the
correct code.
Instances can be obtained by calling the new
method
with method with a variant of the Codes
enum, or by calling the
new_with_func
method with a function
pointer.
Note that since selection of the code happens in the
new
method, it is more efficient to clone a
FuncCodeWriter
than to create a new one.
Implementations§
Source§impl<E: Endianness, CW: CodesWrite<E> + ?Sized> FuncCodeWriter<E, CW>
impl<E: Endianness, CW: CodesWrite<E> + ?Sized> FuncCodeWriter<E, CW>
Sourcepub fn new(code: Codes) -> Result<Self>
pub fn new(code: Codes) -> Result<Self>
Return a new FuncCodeWriter
for the given code.
§Errors
The method will return an error if there is no constant
for the given code in FuncCodeWriter
.
Sourcepub fn new_with_func(
write_func: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>,
) -> Self
pub fn new_with_func( write_func: fn(&mut CW, u64) -> Result<usize, <CW as BitWrite<E>>::Error>, ) -> Self
Return a new FuncCodeWriter
for the given function.
Trait Implementations§
Source§impl<E: Endianness, CR: CodesWrite<E> + ?Sized> Clone for FuncCodeWriter<E, CR>
manually implement Clone to avoid the Clone bound on CR and E
impl<E: Endianness, CR: CodesWrite<E> + ?Sized> Clone for FuncCodeWriter<E, CR>
manually implement Clone to avoid the Clone bound on CR and E