remove Pair

This commit is contained in:
AF 2023-06-28 13:00:38 +00:00
parent 0e8dddfa21
commit bfff862b03

View File

@ -6,25 +6,19 @@ use std::fmt::Display;
use crate::rcore::*; use crate::rcore::*;
use crate::rstd::inlining::{static_pair::*, *}; use crate::rstd::inlining::{static_pair::*, *};
#[derive(Clone)] pub type PairObject<A, B> = StaticPairObject<(A, B)>;
pub struct Pair<A, B> { pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, (A, B)>;
pub a: A,
pub b: B,
}
pub type PairObject<A, B> = StaticPairObject<Pair<A, B>>; impl<A: Serializable, B: Serializable> StaticPairSerializable for (A, B) {
pub type PairFactory<'a, Ctx, A, B> = StaticPairFactory<'a, Ctx, Pair<A, B>>;
impl<A: Serializable, B: Serializable> StaticPairSerializable for Pair<A, B> {
type SA = A; type SA = A;
type SB = B; type SB = B;
fn elements(&self) -> (&Self::SA, &Self::SB) { fn elements(&self) -> (&Self::SA, &Self::SB) {
(&self.a, &self.b) (&self.0, &self.1)
} }
fn into_elements(self) -> (Self::SA, Self::SB) { fn into_elements(self) -> (Self::SA, Self::SB) {
(self.a, self.b) self
} }
} }
@ -50,11 +44,11 @@ impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {} impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {}
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
for Pair<A, B> for (A, B)
where where
A::Fctr: InlineableFactory<'a, Ctx>, A::Fctr: InlineableFactory<'a, Ctx>,
{ {
type FactoryData = Pair<Self::FA, Self::FB>; type FactoryData = (Self::FA, Self::FB);
type A = A; type A = A;
type B = B; type B = B;
type FA = A::Fctr; type FA = A::Fctr;
@ -62,11 +56,11 @@ where
type ParseError = PairParseError<ParseError<'a, Ctx, A::Fctr>, ParseError<'a, Ctx, B::Fctr>>; type ParseError = PairParseError<ParseError<'a, Ctx, A::Fctr>, ParseError<'a, Ctx, B::Fctr>>;
fn factories(factory_data: &Self::FactoryData) -> (&Self::FA, &Self::FB) { fn factories(factory_data: &Self::FactoryData) -> (&Self::FA, &Self::FB) {
(&factory_data.a, &factory_data.b) (&factory_data.0, &factory_data.1)
} }
fn from_parsed(_factory_data: &Self::FactoryData, a: Self::A, b: Self::B) -> Self { fn from_parsed(_factory_data: &Self::FactoryData, a: Self::A, b: Self::B) -> Self {
Pair { a, b } (a, b)
} }
fn from_error_a( fn from_error_a(
@ -84,9 +78,6 @@ where
} }
fn factory_data(&self) -> Self::FactoryData { fn factory_data(&self) -> Self::FactoryData {
Pair { (self.0.factory(), self.1.factory())
a: self.a.factory(),
b: self.b.factory(),
}
} }
} }