pub struct FuncCodeReader<E: Endianness, CR: CodesRead<E> + ?Sized>(/* private fields */);Expand description
A newtype containing a function pointer dispatching the read method for a code.
This is a more efficient way to pass a StaticCodeRead to a method, as a
FuncCodeReader does not need to do a runtime test to dispatch the
correct code.
Instances can be obtained by calling the new 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
FuncCodeReader than to create a new one.
Implementations§
Source§impl<E: Endianness, CR: CodesRead<E> + ?Sized> FuncCodeReader<E, CR>
impl<E: Endianness, CR: CodesRead<E> + ?Sized> FuncCodeReader<E, CR>
Sourcepub const fn new(code: Codes) -> Result<Self, DispatchError>
pub const fn new(code: Codes) -> Result<Self, DispatchError>
Returns a new FuncCodeReader for the given code.
The code is canonicalized before the lookup, so equivalent codes yield the same reader.
§Errors
The method will return an error if there is no constant
for the given code in FuncCodeReader.
Sourcepub const fn new_with_func(
read_func: fn(&mut CR) -> Result<u64, <CR as BitRead<E>>::Error>,
) -> Self
pub const fn new_with_func( read_func: fn(&mut CR) -> Result<u64, <CR as BitRead<E>>::Error>, ) -> Self
Returns a new FuncCodeReader for the given function.