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