use std::{error::Error, sync::Arc};
use crate::func::context::*;
use crate::mode::*;
pub use self::context::Context;
pub use self::demoted::Demoted;
pub use self::diagnostic::Diagnostic;
pub use self::hashing::{Hash, HASH_SIZE, HASH_ZEROS};
pub use self::inctx::InCtx;
pub use self::inlining::{CInliningFactory, IParseResult, InliningFactory};
pub use self::modes::{
ExtensionResultM, ExtensionSourceM, FactoryModeParse, FactoryModeProxy, ModeResultM,
};
pub use self::origin::{OFctr, Origin, OriginMap};
pub use self::point::Point;
pub use self::points::PointsVisitor;
pub use self::regular::{CRegularFactory, RegularFactory};
pub use self::resolution::{
Address, HashResolution, HashResolutionResult, LookupError, Resolution, ResolutionError,
ResolutionFailure, ResolutionResult, Resolver, ResolverMap,
};
pub use self::singular::{SingularError, SingularResolution};
pub use self::to_hex::hex;
pub use self::topology::{MentionableTop, TopoVec, Topology};
mod addresses;
mod context;
mod dectx;
mod demoted;
mod diagnostic;
mod hashing;
mod inctx;
mod inlining;
mod modes;
mod origin;
mod point;
mod points;
mod regular;
mod resolution;
mod resolver_origin;
mod singular;
mod to_hex;
mod topology;
pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>;
pub trait MentionableBase<'a>: 'a + Send + Sync + Serializable + Sized {
type Fctr: FactoryBase<'a, Mtbl = Self>;
fn factory(&self) -> Self::Fctr;
}
pub trait Mentionable<'a, Ctx: Context<'a>>:
MentionableBase<'a, Fctr = Self::_Fctr> + MentionableTop<'a, Ctx>
{
type _Fctr: Factory<'a, Ctx, _Mtbl = Self>;
}
impl<'a, Ctx: Context<'a>, A: MentionableBase<'a> + MentionableTop<'a, Ctx>> Mentionable<'a, Ctx>
for A
where
Self::Fctr: Factory<'a, Ctx, _Mtbl = Self>,
{
type _Fctr = Self::Fctr;
}
pub type Fctr<'a, A> = <A as MentionableBase<'a>>::Fctr;
pub type ParseResult<'a, F> = Result<Mtbl<'a, F>, ParseError<'a, F>>;
pub type ParseResultA<'a, A> = Result<A, ParseErrorA<'a, A>>;
pub trait FactoryBase<'a>: 'a + Send + Sync + Clone {
type Mtbl: MentionableBase<'a, Fctr = Self>;
type ParseError: 'a + Send + Error;
}
pub trait FactoryParse<'a, Ctx: Context<'a>>: FactoryModeParse<'a, Ctx> {
fn deserialize(&self, inctx: impl InCtx<'a, Ctx>) -> ParseResult<'a, Self>;
fn extend(&self, mentionable: Self::Mtbl, tail: &[u8]) -> ParseResult<'a, Self>;
}
pub trait Factory<'a, Ctx: Context<'a>>:
FactoryParse<'a, Ctx, Mtbl = Self::_Mtbl> + ParseMode
{
type _Mtbl: MentionableBase<'a, Fctr = Self> + MentionableTop<'a, Ctx>;
}
impl<'a, Ctx: Context<'a>, F: FactoryParse<'a, Ctx> + ParseMode> Factory<'a, Ctx> for F
where
F::Mtbl: MentionableTop<'a, Ctx>,
{
type _Mtbl = Self::Mtbl;
}
pub type Mtbl<'a, F> = <F as FactoryBase<'a>>::Mtbl;
pub type ParseError<'a, F> = <F as FactoryBase<'a>>::ParseError;
pub type ParseErrorA<'a, A> = ParseError<'a, Fctr<'a, A>>;
pub trait FactoryExt<'a, Ctx: Context<'a>>: FactoryParse<'a, Ctx> {
fn parse_slice(
&self,
slice: &[u8],
resolver: &Arc<dyn Resolver<'a, Ctx>>,
) -> ParseResult<'a, Self>;
}