rcore::inlining
This commit is contained in:
parent
cb56595d45
commit
3b5349de62
@ -6,6 +6,7 @@ mod addresses;
|
||||
mod context;
|
||||
mod diagnostic;
|
||||
mod hashing;
|
||||
mod inlining;
|
||||
mod origin;
|
||||
mod point;
|
||||
mod points;
|
||||
@ -23,6 +24,7 @@ pub use self::addresses::Addresses;
|
||||
pub use self::context::Context;
|
||||
pub use self::diagnostic::Diagnostic;
|
||||
pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS};
|
||||
pub use self::inlining::{Inlining, InliningExt};
|
||||
pub use self::origin::{OFctr, Origin};
|
||||
pub use self::point::Point;
|
||||
pub use self::points::TakesPoints;
|
||||
|
25
src/rcore/inlining.rs
Normal file
25
src/rcore/inlining.rs
Normal file
@ -0,0 +1,25 @@
|
||||
pub trait Inlining: Sized {
|
||||
fn iread_n<A, E>(
|
||||
self,
|
||||
n: usize,
|
||||
ok: impl FnOnce(&[u8]) -> A,
|
||||
err: impl FnOnce(&[u8]) -> E,
|
||||
) -> Result<(A, Self), E>;
|
||||
|
||||
fn itell(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait InliningExt<E>: Inlining {
|
||||
fn iread_n_const<const N: usize>(
|
||||
self,
|
||||
err: impl FnOnce(&[u8]) -> E,
|
||||
) -> Result<([u8; N], Self), E> {
|
||||
self.iread_n(
|
||||
N,
|
||||
|slice| slice.try_into().expect("iread_n wrong length."),
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Inlining, E> InliningExt<E> for D {}
|
@ -10,32 +10,6 @@ use super::{
|
||||
*,
|
||||
};
|
||||
|
||||
pub trait Inlining: Sized {
|
||||
fn iread_n<A, E>(
|
||||
self,
|
||||
n: usize,
|
||||
ok: impl FnOnce(&[u8]) -> A,
|
||||
err: impl FnOnce(&[u8]) -> E,
|
||||
) -> Result<(A, Self), E>;
|
||||
|
||||
fn itell(&self) -> usize;
|
||||
}
|
||||
|
||||
pub trait InliningExt<E>: Inlining {
|
||||
fn iread_n_const<const N: usize>(
|
||||
self,
|
||||
err: impl FnOnce(&[u8]) -> E,
|
||||
) -> Result<([u8; N], Self), E> {
|
||||
self.iread_n(
|
||||
N,
|
||||
|slice| slice.try_into().expect("iread_n wrong length."),
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Inlining, E> InliningExt<E> for D {}
|
||||
|
||||
impl<D: ?Sized + Deserializer> Inlining for &mut D {
|
||||
fn iread_n<A, E>(
|
||||
self,
|
||||
|
Loading…
Reference in New Issue
Block a user