From 3b5349de624d34ef0e39e4383a050859410c4a32 Mon Sep 17 00:00:00 2001 From: timofey Date: Wed, 28 Jun 2023 16:41:37 +0000 Subject: [PATCH] `rcore::inlining` --- src/rcore.rs | 2 ++ src/rcore/inlining.rs | 25 +++++++++++++++++++++++++ src/rstd/inlining.rs | 26 -------------------------- 3 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 src/rcore/inlining.rs diff --git a/src/rcore.rs b/src/rcore.rs index b59bc89..cc72f21 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -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; diff --git a/src/rcore/inlining.rs b/src/rcore/inlining.rs new file mode 100644 index 0000000..7fd57ea --- /dev/null +++ b/src/rcore/inlining.rs @@ -0,0 +1,25 @@ +pub trait Inlining: Sized { + fn iread_n( + self, + n: usize, + ok: impl FnOnce(&[u8]) -> A, + err: impl FnOnce(&[u8]) -> E, + ) -> Result<(A, Self), E>; + + fn itell(&self) -> usize; +} + +pub trait InliningExt: Inlining { + fn iread_n_const( + 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 InliningExt for D {} diff --git a/src/rstd/inlining.rs b/src/rstd/inlining.rs index 41d15ae..0b42caf 100644 --- a/src/rstd/inlining.rs +++ b/src/rstd/inlining.rs @@ -10,32 +10,6 @@ use super::{ *, }; -pub trait Inlining: Sized { - fn iread_n( - self, - n: usize, - ok: impl FnOnce(&[u8]) -> A, - err: impl FnOnce(&[u8]) -> E, - ) -> Result<(A, Self), E>; - - fn itell(&self) -> usize; -} - -pub trait InliningExt: Inlining { - fn iread_n_const( - 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 InliningExt for D {} - impl Inlining for &mut D { fn iread_n( self,