From e9e7ffb57deb91a6b06ebb173e0b58decce2f8b9 Mon Sep 17 00:00:00 2001 From: timofey Date: Fri, 30 Jun 2023 22:12:47 +0000 Subject: [PATCH] `rcore::inctx` --- src/rcore.rs | 2 ++ src/rcore/inctx.rs | 19 +++++++++++++++++++ src/rstd/inlining.rs | 18 ------------------ 3 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 src/rcore/inctx.rs diff --git a/src/rcore.rs b/src/rcore.rs index def07a7..62d415d 100644 --- a/src/rcore.rs +++ b/src/rcore.rs @@ -6,6 +6,7 @@ mod addresses; mod context; mod diagnostic; mod hashing; +mod inctx; mod inlining; mod origin; mod point; @@ -24,6 +25,7 @@ pub use self::addresses::{Addresses, InliningAddresses}; pub use self::context::Context; pub use self::diagnostic::Diagnostic; pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS}; +pub use self::inctx::InCtx; pub use self::inlining::{Inlining, InliningExt}; pub use self::origin::{OFctr, Origin}; pub use self::point::Point; diff --git a/src/rcore/inctx.rs b/src/rcore/inctx.rs new file mode 100644 index 0000000..464d6c9 --- /dev/null +++ b/src/rcore/inctx.rs @@ -0,0 +1,19 @@ +use super::*; + +pub trait InCtx<'a, Ctx: Context<'a>>: Inlining { + fn icnext_address(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E>; + + fn icnext_point<'b, A: Mentionable<'a, Ctx>, E>( + self, + factory: A::Fctr, + err: impl FnOnce(&[u8]) -> E, + ) -> Result<(Point<'a, Ctx, A>, Self), E> { + let (point, inctx) = self.icnext_address(err)?; + Ok(( + Point::from_address(point, factory, inctx.iresolver()), + inctx, + )) + } + + fn iresolver(&self) -> Rc>; +} diff --git a/src/rstd/inlining.rs b/src/rstd/inlining.rs index 257a85e..4df4838 100644 --- a/src/rstd/inlining.rs +++ b/src/rstd/inlining.rs @@ -34,24 +34,6 @@ impl Inlining for &mut D { } } -pub trait InCtx<'a, Ctx: Context<'a>>: Inlining { - fn icnext_address(self, err: impl FnOnce(&[u8]) -> E) -> Result<(Address, Self), E>; - - fn icnext_point<'b, A: Mentionable<'a, Ctx>, E>( - self, - factory: A::Fctr, - err: impl FnOnce(&[u8]) -> E, - ) -> Result<(Point<'a, Ctx, A>, Self), E> { - let (point, inctx) = self.icnext_address(err)?; - Ok(( - Point::from_address(point, factory, inctx.iresolver()), - inctx, - )) - } - - fn iresolver(&self) -> Rc>; -} - impl<'a: 'c, 'c, Ctx: Context<'a>> Inlining for &'c mut dyn DeCtx<'a, Ctx> { fn iread_n( self,