More default handlers
This commit is contained in:
parent
63eaafbe8f
commit
b9c25c93cc
@ -1,4 +1,4 @@
|
|||||||
use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler};
|
use crate::dsl::{BooleanHandler, NoValueHandler, NullHandler};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub struct Handler_Boolean<
|
pub struct Handler_Boolean<
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use crate::dsl::{FloatHandler, IntegerHandler};
|
use crate::dsl::FloatHandler;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
pub struct Handler_F64<
|
pub struct Handler_F64<
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
mod integers;
|
|
||||||
mod floats;
|
|
||||||
mod enums;
|
mod enums;
|
||||||
|
mod floats;
|
||||||
|
mod integers;
|
||||||
|
mod noop;
|
||||||
|
mod string;
|
||||||
|
mod value;
|
||||||
|
|
||||||
pub use integers::*;
|
|
||||||
pub use floats::*;
|
|
||||||
pub use enums::*;
|
pub use enums::*;
|
||||||
|
pub use floats::*;
|
||||||
|
pub use integers::*;
|
||||||
|
pub use noop::*;
|
||||||
|
pub use string::*;
|
||||||
|
pub use value::*;
|
||||||
|
|||||||
110
src/default_handlers/noop.rs
Normal file
110
src/default_handlers/noop.rs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
use crate::dsl::{
|
||||||
|
ArrayConfiguration, ArrayConfigurationScope, ArrayHandler, BooleanHandler, FloatHandler,
|
||||||
|
IntegerHandler, NullHandler, ObjectConfiguration, ObjectConfigurationScope, ObjectHandler,
|
||||||
|
StringHandler,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Handler_Error {}
|
||||||
|
|
||||||
|
fn _throw() -> ! {
|
||||||
|
panic!(
|
||||||
|
"This handler used to specify generic param for Option::None and don't designed to be called"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized> IntegerHandler<Runtime, Container> for Handler_Error {
|
||||||
|
fn handleFixedInteger(&self, _: &mut Runtime, _: &mut Container, _: u64, _: bool) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized> FloatHandler<Runtime, Container> for Handler_Error {
|
||||||
|
fn handleFloat(&self, _: &mut Runtime, _: &mut Container, _: f64) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized> BooleanHandler<Runtime, Container> for Handler_Error {
|
||||||
|
fn handleBoolean(&self, _: &mut Runtime, _: &mut Container, _: bool) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized> NullHandler<Runtime, Container> for Handler_Error {
|
||||||
|
fn handleNull(&self, _: &mut Runtime, _: &mut Container) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized> NoValueHandler<Runtime, Container> for Handler_Error {
|
||||||
|
fn handleNoValue(&self, _: &mut Runtime, _: &mut Container) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, ObjectBuilder>
|
||||||
|
ObjectHandler<Runtime, Container, ObjectBuilder> for Handler_Error
|
||||||
|
{
|
||||||
|
fn produceObject(&self, _: &mut Runtime) -> ObjectBuilder {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn storeObject(&self, _: &mut Runtime, _: &mut Container, _: ObjectBuilder) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, ArrayBuilder>
|
||||||
|
ArrayHandler<Runtime, Container, ArrayBuilder> for Handler_Error
|
||||||
|
{
|
||||||
|
fn produceArray(&self, _: &mut Runtime) -> ArrayBuilder {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn storeArray(&self, _: &mut Runtime, _: &mut Container, _: ArrayBuilder) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, String> StringHandler<Runtime, Container, String>
|
||||||
|
for Handler_Error
|
||||||
|
{
|
||||||
|
fn handleString(&self, _: &mut Runtime, _: &mut Container, _: String) {
|
||||||
|
_throw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, ObjectBuilder>
|
||||||
|
ObjectConfiguration<Runtime, Container, ObjectBuilder> for Handler_Error
|
||||||
|
{
|
||||||
|
type ObjectBuilder = ();
|
||||||
|
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
fn configureObject(
|
||||||
|
&self,
|
||||||
|
_: &impl ObjectConfigurationScope<Runtime, Self::ObjectBuilder, ObjectBuilder>,
|
||||||
|
) -> impl ObjectHandler<Runtime, Container, Self::ObjectBuilder> {
|
||||||
|
_throw();
|
||||||
|
// return type deducing:
|
||||||
|
return Handler_Error::default();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, ObjectBuilder>
|
||||||
|
ArrayConfiguration<Runtime, Container, ObjectBuilder> for Handler_Error
|
||||||
|
{
|
||||||
|
type ArrayBuilder = ();
|
||||||
|
|
||||||
|
#[allow(unreachable_code)]
|
||||||
|
fn configureArray(
|
||||||
|
&self,
|
||||||
|
_: &impl ArrayConfigurationScope<Runtime, Self::ArrayBuilder, ObjectBuilder>,
|
||||||
|
) -> impl ObjectHandler<Runtime, Container, Self::ArrayBuilder> {
|
||||||
|
_throw();
|
||||||
|
// return type deducing:
|
||||||
|
return Handler_Error::default();
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/default_handlers/string.rs
Normal file
32
src/default_handlers/string.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use crate::dsl::StringHandler;
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
pub struct Handler_String<
|
||||||
|
Runtime: ?Sized,
|
||||||
|
Container: ?Sized,
|
||||||
|
String,
|
||||||
|
StoreFn: Fn(&mut Runtime, &mut Container, String),
|
||||||
|
> {
|
||||||
|
store: StoreFn,
|
||||||
|
__phantom: PhantomData<(*const Runtime, *const Container, String)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, String, StoreFn: Fn(&mut Runtime, &mut Container, String)>
|
||||||
|
Handler_String<Runtime, Container, String, StoreFn>
|
||||||
|
{
|
||||||
|
pub fn create(f: StoreFn) -> Self {
|
||||||
|
return Self {
|
||||||
|
store: f,
|
||||||
|
__phantom: PhantomData::default(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Runtime: ?Sized, Container: ?Sized, String, StoreFn: Fn(&mut Runtime, &mut Container, String)>
|
||||||
|
StringHandler<Runtime, Container, String>
|
||||||
|
for Handler_String<Runtime, Container, String, StoreFn>
|
||||||
|
{
|
||||||
|
fn handleString(&self, runtime: &mut Runtime, dst: &mut Container, value: String) {
|
||||||
|
(self.store)(runtime, dst, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
82
src/default_handlers/value.rs
Normal file
82
src/default_handlers/value.rs
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
use crate::dsl::{
|
||||||
|
ArrayConfiguration, BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler,
|
||||||
|
ObjectConfiguration, StringHandler, ValueConfiguration,
|
||||||
|
};
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
pub struct DefaultValueConfig<
|
||||||
|
Runtime: ?Sized,
|
||||||
|
Container: ?Sized,
|
||||||
|
String,
|
||||||
|
HInteger: IntegerHandler<Runtime, Container> + Clone,
|
||||||
|
HFloat: FloatHandler<Runtime, Container> + Clone,
|
||||||
|
HBoolean: BooleanHandler<Runtime, Container> + Clone,
|
||||||
|
HNull: NullHandler<Runtime, Container> + Clone,
|
||||||
|
HObject: ObjectConfiguration<Runtime, Container, String> + Clone,
|
||||||
|
HArray: ArrayConfiguration<Runtime, Container, String> + Clone,
|
||||||
|
HString: StringHandler<Runtime, Container, String> + Clone,
|
||||||
|
> {
|
||||||
|
pub int: Option<HInteger>,
|
||||||
|
pub float: Option<HFloat>,
|
||||||
|
pub bool: Option<HBoolean>,
|
||||||
|
pub null: Option<HNull>,
|
||||||
|
pub object: Option<HObject>,
|
||||||
|
pub array: Option<HArray>,
|
||||||
|
pub string: Option<HString>,
|
||||||
|
|
||||||
|
pub __phantom: PhantomData<(*const Runtime, *const Container, String)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<
|
||||||
|
Runtime: ?Sized,
|
||||||
|
Container: ?Sized,
|
||||||
|
String,
|
||||||
|
HInteger: IntegerHandler<Runtime, Container> + Clone,
|
||||||
|
HFloat: FloatHandler<Runtime, Container> + Clone,
|
||||||
|
HBoolean: BooleanHandler<Runtime, Container> + Clone,
|
||||||
|
HNull: NullHandler<Runtime, Container> + Clone,
|
||||||
|
HObject: ObjectConfiguration<Runtime, Container, String> + Clone,
|
||||||
|
HArray: ArrayConfiguration<Runtime, Container, String> + Clone,
|
||||||
|
HString: StringHandler<Runtime, Container, String> + Clone,
|
||||||
|
> ValueConfiguration<Runtime, Container, String>
|
||||||
|
for DefaultValueConfig<
|
||||||
|
Runtime,
|
||||||
|
Container,
|
||||||
|
String,
|
||||||
|
HInteger,
|
||||||
|
HFloat,
|
||||||
|
HBoolean,
|
||||||
|
HNull,
|
||||||
|
HObject,
|
||||||
|
HArray,
|
||||||
|
HString,
|
||||||
|
>
|
||||||
|
{
|
||||||
|
fn integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>> {
|
||||||
|
return self.int.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>> {
|
||||||
|
return self.float.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>> {
|
||||||
|
return self.bool.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>> {
|
||||||
|
return self.null.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn objectHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container, String>> {
|
||||||
|
return self.object.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn arrayHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container, String>> {
|
||||||
|
return self.array.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container, String>> {
|
||||||
|
return self.string.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/dsl.rs
36
src/dsl.rs
@ -1,3 +1,5 @@
|
|||||||
|
use crate::default_handlers::Handler_Error;
|
||||||
|
|
||||||
pub trait IntegerHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
|
pub trait IntegerHandler<Runtime: ?Sized, Container: ?Sized>: Sized {
|
||||||
fn handleFixedInteger(
|
fn handleFixedInteger(
|
||||||
&self,
|
&self,
|
||||||
@ -89,11 +91,31 @@ pub trait ArrayConfigurationScope<Runtime: ?Sized, Container: ?Sized, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait ValueConfiguration<Runtime: ?Sized, Container: ?Sized, String>: Sized {
|
pub trait ValueConfiguration<Runtime: ?Sized, Container: ?Sized, String>: Sized {
|
||||||
fn integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>>;
|
fn integerHandler(&self) -> Option<impl IntegerHandler<Runtime, Container>> {
|
||||||
fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>>;
|
return None::<Handler_Error>;
|
||||||
fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>>;
|
}
|
||||||
fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>>;
|
|
||||||
fn objectHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container, String>>;
|
fn floatHandler(&self) -> Option<impl FloatHandler<Runtime, Container>> {
|
||||||
fn arrayHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container, String>>;
|
return None::<Handler_Error>;
|
||||||
fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container, String>>;
|
}
|
||||||
|
|
||||||
|
fn booleanHandler(&self) -> Option<impl BooleanHandler<Runtime, Container>> {
|
||||||
|
return None::<Handler_Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nullHandler(&self) -> Option<impl NullHandler<Runtime, Container>> {
|
||||||
|
return None::<Handler_Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn objectHandler(&self) -> Option<impl ObjectConfiguration<Runtime, Container, String>> {
|
||||||
|
return None::<Handler_Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn arrayHandler(&self) -> Option<impl ArrayConfiguration<Runtime, Container, String>> {
|
||||||
|
return None::<Handler_Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stringHandler(&self) -> Option<impl StringHandler<Runtime, Container, String>> {
|
||||||
|
return None::<Handler_Error>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
pub mod dsl;
|
|
||||||
pub mod default_handlers;
|
pub mod default_handlers;
|
||||||
|
pub mod dsl;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user