rcore::context

This commit is contained in:
AF 2023-05-30 15:08:40 +00:00
parent 8997900157
commit f4a3220548
2 changed files with 22 additions and 19 deletions

View File

@ -3,6 +3,7 @@
//! Allows for more generic behaviour via [`Context`], as opposed to original async-only. //! Allows for more generic behaviour via [`Context`], as opposed to original async-only.
mod addresses; mod addresses;
mod context;
mod diagnostic; mod diagnostic;
mod hashing; mod hashing;
mod origin; mod origin;
@ -18,6 +19,7 @@ use std::{error::Error, rc::Rc};
use crate::func::*; use crate::func::*;
pub use self::addresses::Addresses; pub use self::addresses::Addresses;
pub use self::context::Context;
pub use self::diagnostic::Diagnostic; pub use self::diagnostic::Diagnostic;
pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS}; pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS};
pub use self::origin::{OFctr, Origin}; pub use self::origin::{OFctr, Origin};
@ -30,25 +32,6 @@ pub use self::resolution::{
pub use self::serialization::{Deserializer, DeserializerExt, Serializable, Serializer}; pub use self::serialization::{Deserializer, DeserializerExt, Serializable, Serializer};
pub use self::slice_deserializer::SliceDeserializer; pub use self::slice_deserializer::SliceDeserializer;
/// Execution context.
pub trait Context<'a>: 'a {
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
type T: Monad<'a>;
/// Type to allow improved support for result evaluation.
/// This is important for async applications stopping early.
type Fallible: MonadFailAny<'a, T = Self::T>;
/// See [`Diagnostic`].
type D: Diagnostic<'a, Self::T>;
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
type LookupError: 'a + Error;
/// Get [type@Hash] of a slice, mostly for use in [`Point`].
fn hash(s: &[u8]) -> Hash;
}
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`]. /// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context<'a>>::T>; pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context<'a>>::T>;

20
src/rcore/context.rs Normal file
View File

@ -0,0 +1,20 @@
use super::*;
/// Execution context.
pub trait Context<'a>: 'a {
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
type T: Monad<'a>;
/// Type to allow improved support for result evaluation.
/// This is important for async applications stopping early.
type Fallible: MonadFailAny<'a, T = Self::T>;
/// See [`Diagnostic`].
type D: Diagnostic<'a, Self::T>;
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
type LookupError: 'a + Error;
/// Get [type@Hash] of a slice, mostly for use in [`Point`].
fn hash(s: &[u8]) -> Hash;
}