Context
via FunctorContext
This commit is contained in:
parent
f4a3220548
commit
277bea3eb3
@ -16,6 +16,7 @@ mod slice_deserializer;
|
||||
|
||||
use std::{error::Error, rc::Rc};
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::func::*;
|
||||
|
||||
pub use self::addresses::Addresses;
|
||||
@ -32,8 +33,8 @@ pub use self::resolution::{
|
||||
pub use self::serialization::{Deserializer, DeserializerExt, Serializable, Serializer};
|
||||
pub use self::slice_deserializer::SliceDeserializer;
|
||||
|
||||
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
|
||||
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context<'a>>::T>;
|
||||
/// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`].
|
||||
pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>;
|
||||
|
||||
/// Fundamental trait for ADN objects.
|
||||
pub trait Mentionable<'a, Ctx: Context<'a>>: 'a + Serializable {
|
||||
|
@ -1,9 +1,9 @@
|
||||
use super::*;
|
||||
|
||||
/// Execution context.
|
||||
pub trait Context<'a>: 'a {
|
||||
pub trait Context<'a>: FunctorContext<'a, T = Self::_Tm> {
|
||||
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
|
||||
type T: Monad<'a>;
|
||||
type _Tm: Monad<'a>;
|
||||
|
||||
/// Type to allow improved support for result evaluation.
|
||||
/// This is important for async applications stopping early.
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! Shorthands for using [`Context::Fallible`].
|
||||
|
||||
#[cfg(doc)]
|
||||
use crate::func::context::FunctorContext;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Preferred monad for fallible uses.
|
||||
@ -8,7 +11,7 @@ pub type FallibleMonad<'a, Ctx, E> = <<Ctx as Context<'a>>::Fallible as MonadFai
|
||||
/// Preferred [Wrapped] [Result].
|
||||
pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<'a, Ctx, E>>;
|
||||
|
||||
/// Extention trait for simpler conversion between [`Context::T`] and [`Context::Fallible`].
|
||||
/// Extention trait for simpler conversion between [`FunctorContext::T`] and [`Context::Fallible`].
|
||||
///
|
||||
/// Until either Rust type system or [`crate::func`] take serious changes,
|
||||
/// this is the preferred way to switch between [Wrapped] and [fallible].
|
||||
|
@ -6,13 +6,13 @@ struct TracedResolver<'a, Ctx: Context<'a>> {
|
||||
resolver: Rc<dyn Resolver<'a, Ctx>>,
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a, T = TracedInstance>> TracedResolver<'a, Ctx> {
|
||||
impl<'a, Ctx: Context<'a, _Tm = TracedInstance>> TracedResolver<'a, Ctx> {
|
||||
fn wrap(resolver: Rc<dyn Resolver<'a, Ctx>>) -> Rc<dyn Resolver<'a, Ctx>> {
|
||||
Rc::new(Self { resolver })
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a, T = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
|
||||
impl<'a, Ctx: Context<'a, _Tm = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
|
||||
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
|
||||
TracedInstance::fmap(self.resolver.clone().resolve(address), |resolved| {
|
||||
let (src, resolver) = resolved?;
|
||||
@ -24,7 +24,7 @@ impl<'a, Ctx: Context<'a, T = TracedInstance>> Resolver<'a, Ctx> for TracedResol
|
||||
}
|
||||
|
||||
/// Extension trait to trace the evaluation flow.
|
||||
pub trait Traceable<'a, Ctx: Context<'a, T = TracedInstance>>:
|
||||
pub trait Traceable<'a, Ctx: Context<'a, _Tm = TracedInstance>>:
|
||||
Mentionable<'a, Ctx> + Sized
|
||||
{
|
||||
/// Re-cast the value, adding an extra[^extra]
|
||||
@ -35,7 +35,7 @@ pub trait Traceable<'a, Ctx: Context<'a, T = TracedInstance>>:
|
||||
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>;
|
||||
}
|
||||
|
||||
impl<'a, Ctx: Context<'a, T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
|
||||
impl<'a, Ctx: Context<'a, _Tm = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
|
||||
where
|
||||
Ctx::LookupError: From<CastError<'a>>,
|
||||
{
|
||||
|
@ -6,10 +6,9 @@ use std::{error::Error, fmt::Display, rc::Rc};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::func::*;
|
||||
use crate::func::{context::FunctorContext, *};
|
||||
use crate::rcore::*;
|
||||
use crate::rstd::cast::*;
|
||||
use crate::rstd::typeless::*;
|
||||
use crate::rstd::{cast::*, typeless::*};
|
||||
|
||||
pub struct NoDiagnostic;
|
||||
|
||||
@ -67,8 +66,12 @@ impl<'a> Display for TestLookupError<'a> {
|
||||
|
||||
impl<'a> Error for TestLookupError<'a> {}
|
||||
|
||||
impl<'a> Context<'a> for TestContextPlain {
|
||||
impl<'a> FunctorContext<'a> for TestContextPlain {
|
||||
type T = instances::solo::SoloInstance;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextPlain {
|
||||
type _Tm = Self::T;
|
||||
|
||||
type Fallible = instances::result::ResultFailAny;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::func::*;
|
||||
use crate::func::{context::*, *};
|
||||
use crate::rcore::*;
|
||||
use crate::rstd::typeless::*;
|
||||
|
||||
@ -8,8 +8,12 @@ use super::*;
|
||||
|
||||
pub struct TestContextCounted;
|
||||
|
||||
impl<'a> Context<'a> for TestContextCounted {
|
||||
impl<'a> FunctorContext<'a> for TestContextCounted {
|
||||
type T = CountedInstance;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextCounted {
|
||||
type _Tm = Self::T;
|
||||
|
||||
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::func::context::*;
|
||||
use crate::rcore::*;
|
||||
use crate::rstd::tracing::*;
|
||||
|
||||
@ -5,8 +6,12 @@ use super::*;
|
||||
|
||||
pub struct TestContextTraced;
|
||||
|
||||
impl<'a> Context<'a> for TestContextTraced {
|
||||
impl<'a> FunctorContext<'a> for TestContextTraced {
|
||||
type T = TracedInstance;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextTraced {
|
||||
type _Tm = Self::T;
|
||||
|
||||
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user