AtomicBase for StaticPairObject
This commit is contained in:
parent
248d5fe15d
commit
3a62d362e5
@ -29,7 +29,7 @@ pub type AParseError<A> = <A as AtomicBase>::AParseError;
|
||||
pub type AParseResult<A> = Result<A, AParseError<A>>;
|
||||
|
||||
/// [`Atomic`] base.
|
||||
pub trait AtomicBase: 'static + Send + Sync + Send + Clone + Serializable {
|
||||
pub trait AtomicBase: 'static + Send + Sync + Clone + Serializable {
|
||||
/// Equivalent of [`FactoryBase::ParseError`].
|
||||
///
|
||||
/// [`FactoryBase::ParseError`]: crate::rcore::FactoryBase::ParseError
|
||||
|
@ -68,6 +68,7 @@ pub trait StaticPair<'a, Ctx: Context<'a>>:
|
||||
}
|
||||
|
||||
/// Generic implementation of a [Mentionable] for [StaticPair]s.
|
||||
#[derive(Clone)]
|
||||
pub struct StaticPairObject<SP> {
|
||||
pair: SP,
|
||||
}
|
||||
@ -205,3 +206,24 @@ where
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user