pub struct DecodeLifecycleProgress<V> { /* private fields */ }Expand description
Main decoded value and lifecycle output lengths written to caller storage.
§Type Parameters
V: Logical value type produced by the codec.
§Examples
use core::convert::Infallible;
use core::num::NonZeroUsize;
use qubit_codec::Codec;
use qubit_codec::CodecValueDecoder;
use qubit_codec::DecodeFailure;
use qubit_codec::DecodeLifecycleProgress;
struct ByteCodec;
impl Codec for ByteCodec {
type Value = u8;
type Unit = u8;
type DecodeError = Infallible;
type EncodeError = Infallible;
const MIN_UNITS_PER_VALUE: usize = 1;
const MAX_ENCODE_UNITS_PER_VALUE: usize = 1;
const MAX_DECODE_UNITS_PER_VALUE: usize = 1;
unsafe fn decode(&mut self, input: &[u8], index: usize)
-> Result<(u8, NonZeroUsize), DecodeFailure<Infallible>>
{
Ok((input[index], NonZeroUsize::MIN))
}
unsafe fn encode(&mut self, value: &u8, output: &mut [u8], index: usize)
-> Result<usize, Infallible>
{
output[index] = *value;
Ok(1)
}
}
let mut decoder = CodecValueDecoder::new(ByteCodec);
let progress: DecodeLifecycleProgress<u8> = decoder
.decode_lifecycle_with_scratch(&[42], &mut [], &mut [])
.unwrap();
assert_eq!(*progress.value(), 42);
assert_eq!(progress.reset_written(), 0);
assert_eq!(progress.finish_written(), 0);Implementations§
Source§impl<V> DecodeLifecycleProgress<V>
impl<V> DecodeLifecycleProgress<V>
Sourcepub const fn value(&self) -> &V
pub const fn value(&self) -> &V
Returns the main value decoded from the supplied input.
§Returns
Returns a shared reference to the main decoded value.
Sourcepub const fn reset_written(&self) -> usize
pub const fn reset_written(&self) -> usize
Returns the number of reset values written to caller storage.
§Returns
Returns the initialized reset output length.
Sourcepub const fn finish_written(&self) -> usize
pub const fn finish_written(&self) -> usize
Returns the number of finish values written to caller storage.
§Returns
Returns the initialized finish output length.
Sourcepub fn into_parts(self) -> (V, usize, usize)
pub fn into_parts(self) -> (V, usize, usize)
Consumes this progress and returns its components.
§Returns
Returns the main value, reset output length, and finish output length.
Trait Implementations§
Source§impl<V: Clone> Clone for DecodeLifecycleProgress<V>
impl<V: Clone> Clone for DecodeLifecycleProgress<V>
impl<V: Copy> Copy for DecodeLifecycleProgress<V>
Source§impl<V: Debug> Debug for DecodeLifecycleProgress<V>
impl<V: Debug> Debug for DecodeLifecycleProgress<V>
impl<V: Eq> Eq for DecodeLifecycleProgress<V>
Source§impl<V: Hash> Hash for DecodeLifecycleProgress<V>
impl<V: Hash> Hash for DecodeLifecycleProgress<V>
Source§impl<V: PartialEq> PartialEq for DecodeLifecycleProgress<V>
impl<V: PartialEq> PartialEq for DecodeLifecycleProgress<V>
impl<V: PartialEq> StructuralPartialEq for DecodeLifecycleProgress<V>
Auto Trait Implementations§
impl<V> Forget for DecodeLifecycleProgress<V>
impl<V> Freeze for DecodeLifecycleProgress<V>where
V: Freeze,
impl<V> RefUnwindSafe for DecodeLifecycleProgress<V>where
V: RefUnwindSafe,
impl<V> Send for DecodeLifecycleProgress<V>where
V: Send,
impl<V> Sync for DecodeLifecycleProgress<V>where
V: Sync,
impl<V> Unpin for DecodeLifecycleProgress<V>where
V: Unpin,
impl<V> UnsafeUnpin for DecodeLifecycleProgress<V>where
V: UnsafeUnpin,
impl<V> UnwindSafe for DecodeLifecycleProgress<V>where
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more