Inlining docs

This commit is contained in:
AF 2023-07-01 00:02:16 +00:00
parent d9d50e8bc0
commit 7e4966e2b8

View File

@ -1,6 +1,9 @@
use super::*;
/// [`Deserializer`] with a cleaner interface for parsing multiple objects
/// from one stream ("inlining").
pub trait Inlining: Sized {
/// Try to read `n` bytes. Consumes the deserializer on failure.
fn iread_n<A, E>(
self,
n: usize,
@ -8,8 +11,10 @@ pub trait Inlining: Sized {
err: impl FnOnce(&[u8]) -> E,
) -> Result<(A, Self), E>;
/// Read all bytes, consuming the deserializer.
fn iread_all<A>(self, ok: impl FnOnce(&[u8]) -> A) -> A;
/// Re-export of [`Deserializer::tell`].
fn itell(&self) -> usize;
}
@ -20,7 +25,7 @@ pub trait InliningExt<E>: Inlining {
) -> Result<([u8; N], Self), E> {
self.iread_n(
N,
|slice| slice.try_into().expect("iread_n wrong length."),
|slice| slice.try_into().expect("`iread_n` wrong length."),
err,
)
}