AtomicBase for StaticPairObject

This commit is contained in:
AF 2023-08-04 18:20:34 +00:00
parent 248d5fe15d
commit 3a62d362e5
2 changed files with 23 additions and 1 deletions

View File

@ -29,7 +29,7 @@ pub type AParseError<A> = <A as AtomicBase>::AParseError;
pub type AParseResult<A> = Result<A, AParseError<A>>; pub type AParseResult<A> = Result<A, AParseError<A>>;
/// [`Atomic`] base. /// [`Atomic`] base.
pub trait AtomicBase: 'static + Send + Sync + Send + Clone + Serializable { pub trait AtomicBase: 'static + Send + Sync + Clone + Serializable {
/// Equivalent of [`FactoryBase::ParseError`]. /// Equivalent of [`FactoryBase::ParseError`].
/// ///
/// [`FactoryBase::ParseError`]: crate::rcore::FactoryBase::ParseError /// [`FactoryBase::ParseError`]: crate::rcore::FactoryBase::ParseError

View File

@ -68,6 +68,7 @@ pub trait StaticPair<'a, Ctx: Context<'a>>:
} }
/// Generic implementation of a [Mentionable] for [StaticPair]s. /// Generic implementation of a [Mentionable] for [StaticPair]s.
#[derive(Clone)]
pub struct StaticPairObject<SP> { pub struct StaticPairObject<SP> {
pair: SP, pair: SP,
} }
@ -205,3 +206,24 @@ where
{ {
const SIZE: usize = SP::FA::SIZE + SP::FB::SIZE; const SIZE: usize = SP::FA::SIZE + SP::FB::SIZE;
} }
pub trait StaticPairAtomic:
'static + Send + Sync + Clone + Sized + StaticPairSerializable<SA = Self::A, SB = Self::B>
{
/// First element's type. Must equal [`StaticPairSerializable::SA`].
type A: AtomicBase;
/// Second element's type. Must equal [`StaticPairSerializable::SB`].
type B: AtomicBase;
type AParseError: Error;
/// Construct the atomic from the elements.
fn from_parsed(a: Self::A, b: Self::B) -> Result<Self, Self::AParseError>;
/// Regularise the error returned while parsing the first element.
fn from_error_a(error: AParseError<Self::A>) -> Self::AParseError;
/// Regularise the error returned while parsing the second element.
fn from_error_b(error: AParseError<Self::B>) -> Self::AParseError;
}
impl<SP: StaticPairAtomic> AtomicBase for StaticPairObject<SP> {
type AParseError = SP::AParseError;
}