Extended DSL traits with runtime parameter

This commit is contained in:
Andrew Golovashevich 2025-12-07 16:18:59 +03:00
parent 9ac06199bd
commit d6c87db64f

View File

@ -1,88 +1,95 @@
pub trait IntegerHandler<S>: Sized { pub trait IntegerHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
fn handleFixedInteger(&self, dst: &mut S, value: u64, isNegative: bool); fn handleFixedInteger(
} &self,
runtime: &mut Runtime,
pub trait FloatHandler<S>: Sized { dst: &mut Container,
fn handleFloat(&self, dst: &mut S, value: f64); value: u64,
} isNegative: bool,
pub trait BooleanHandler<S>: Sized {
fn handleBoolean(&self, dst: &mut S, value: bool);
}
pub trait NullHandler<S>: Sized {
fn handleNull(&self, dst: &mut S);
}
pub trait NoValueHandler<S>: Sized {
fn handleNoValue(&self, dst: &mut S);
}
pub trait ObjectHandler<P, S>: Sized {
fn produceObject(&self) -> S;
fn storeObject(&self, dst: &mut P, value: S);
}
pub trait StringHandler<P, T>: Sized {
fn handleString(&self, dst: &mut P, value: T);
}
pub trait ObjectConfigurationScope<S> {
type K;
fn ignoreKey_required(&mut self, name: &Self::K);
fn ignoreKey_optional(&mut self, name: &Self::K);
fn processKey(&mut self, name: &Self::K, config: impl ValueConfiguration<S>);
fn processKey_optional(
&mut self,
name: &Self::K,
config: impl ValueConfiguration<S>,
fallback: impl NoValueHandler<S>,
); );
} }
pub trait ObjectConfiguration<P>: Sized {
type S: Sized; pub trait FloatHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64);
}
pub trait BooleanHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
fn handleBoolean(&self, runtime: &mut Runtime, dst: &mut Container, value: bool);
}
pub trait NullHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
fn handleNull(&self, runtime: &mut Runtime, dst: &mut Container);
}
pub trait NoValueHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
fn handleNoValue(&self, runtime: &mut Runtime, dst: &mut Container);
}
pub trait StringHandler<Runtime: ?Sized, Container: ?Sized, String>: Sized {
fn handleString(&self, runtime: &mut Runtime, dst: &mut Container, value: String);
}
pub trait ObjectHandler<Runtime: ?Sized, ParentContainer: ?Sized, ObjectBuilder>: Sized {
fn produceObject(&self, runtime: &mut Runtime) -> ObjectBuilder;
fn storeObject(&self, runtime: &mut Runtime, dst: &mut ParentContainer, value: ObjectBuilder);
}
pub trait ArrayHandler<Runtime: ?Sized, ParentContainer: ?Sized, ArrayBuilder>: Sized {
fn produceArray(&self, runtime: &mut Runtime) -> ArrayBuilder;
fn storeArray(&self, runtime: &mut Runtime, dst: &mut ParentContainer, value: ArrayBuilder);
}
pub trait ObjectConfiguration<Runtime: ?Sized, ParentContainer: ?Sized>: Sized {
type ObjectBuilder: Sized;
fn configureObject( fn configureObject(
&self, &self,
scope: &impl ArrayConfigurationScope<Self::S>, scope: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder>,
) -> impl ObjectHandler<P, Self::S>; ) -> impl ObjectHandler<Runtime, ParentContainer, Self::ObjectBuilder>;
} }
pub trait ArrayHandler<P, S>: Sized { pub trait ArrayConfiguration<Runtime: ?Sized, ParentContainer: ?Sized>: Sized {
fn produceArray(&self) -> S; type ArrayBuilder: Sized;
fn storeArray(&self, dst: &mut P, value: S); fn configureArray(
&self,
scope: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder>,
) -> impl ObjectHandler<Runtime, ParentContainer, Self::ArrayBuilder>;
} }
pub trait ArrayConfigurationScope<S> { pub trait ObjectConfigurationScope<Runtime: ?Sized, Container: ?Sized> {
type Key: Sized;
fn ignoreKey_required(&mut self, name: Self::Key);
fn ignoreKey_optional(&mut self, name: Self::Key);
fn processKey(&mut self, name: Self::Key, config: impl ValueConfiguration<Runtime, Container>);
fn processKey_optional(
&mut self,
name: Self::Key,
config: impl ValueConfiguration<Runtime, Container>,
fallback: impl NoValueHandler<Runtime, Container>,
);
}
pub trait ArrayConfigurationScope<Runtime: ?Sized, Container: ?Sized> {
fn ignoreElements_required(&self, start: usize, endInclusive: Option<usize>); fn ignoreElements_required(&self, start: usize, endInclusive: Option<usize>);
fn ignoreElements_optional(&self, start: usize, endInclusive: Option<usize>); fn ignoreElements_optional(&self, start: usize, endInclusive: Option<usize>);
fn processElements_required( fn processElements_required(
&self, &self,
start: usize, start: usize,
endInclusive: Option<usize>, endInclusive: Option<usize>,
config: impl ValueConfiguration<S>, config: impl ValueConfiguration<Runtime, Container>,
); );
fn processElements_optional( fn processElements_optional(
&self, &self,
start: usize, start: usize,
endInclusive: Option<usize>, endInclusive: Option<usize>,
config: impl ValueConfiguration<S>, config: impl ValueConfiguration<Runtime, Container>
); );
} }
pub trait ArrayConfiguration<P>: Sized { pub trait ValueConfiguration<Runtime: ?Sized, Container: ?Sized>: Sized {
type S: Sized; fn integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>>;
fn configureArray( fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>>;
&self, fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>>;
scope: &impl ArrayConfigurationScope<Self::S>, fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>>;
) -> impl ObjectHandler<P, Self::S>; fn arrayHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container>>;
} fn objectHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container>>;
// fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container>>;
pub trait ValueConfiguration<P>: Sized {
fn integerHandler(&self) -> Option<impl IntegerHandler<P>>;
fn floatHandler(&self) -> Option<impl FloatHandler<P>>;
fn booleanHandler(&self) -> Option<impl BooleanHandler<P>>;
fn nullHandler(&self) -> Option<impl NullHandler<P>>;
fn arrayHandler(&self) -> Option<impl ObjectConfiguration<P>>;
fn objectHandler(&self) -> Option<impl ArrayConfiguration<P>>;
} }