From b9c25c93cc44d30d3809b282446de2a17f67d094 Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Sun, 7 Dec 2025 20:51:24 +0300 Subject: [PATCH] More default handlers --- src/default_handlers/enums.rs | 2 +- src/default_handlers/floats.rs | 8 +-- src/default_handlers/mod.rs | 14 +++-- src/default_handlers/noop.rs | 110 +++++++++++++++++++++++++++++++++ src/default_handlers/string.rs | 32 ++++++++++ src/default_handlers/value.rs | 82 ++++++++++++++++++++++++ src/dsl.rs | 36 ++++++++--- src/lib.rs | 2 +- 8 files changed, 269 insertions(+), 17 deletions(-) create mode 100644 src/default_handlers/noop.rs create mode 100644 src/default_handlers/string.rs create mode 100644 src/default_handlers/value.rs diff --git a/src/default_handlers/enums.rs b/src/default_handlers/enums.rs index 46dbc4c..c634708 100644 --- a/src/default_handlers/enums.rs +++ b/src/default_handlers/enums.rs @@ -1,4 +1,4 @@ -use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler}; +use crate::dsl::{BooleanHandler, NoValueHandler, NullHandler}; use std::marker::PhantomData; pub struct Handler_Boolean< diff --git a/src/default_handlers/floats.rs b/src/default_handlers/floats.rs index 312f6b6..1452af2 100644 --- a/src/default_handlers/floats.rs +++ b/src/default_handlers/floats.rs @@ -1,4 +1,4 @@ -use crate::dsl::{FloatHandler, IntegerHandler}; +use crate::dsl::FloatHandler; use std::marker::PhantomData; pub struct Handler_F64< @@ -36,7 +36,7 @@ pub struct Handler_F32< __phantom: PhantomData<(*const Runtime, *const Container)>, } impl -Handler_F32 + Handler_F32 { pub fn create(f: StoreFn) -> Self { return Self { @@ -46,9 +46,9 @@ Handler_F32 } } impl -FloatHandler for Handler_F32 + FloatHandler for Handler_F32 { fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64) { (self.store)(runtime, dst, value as f32); } -} \ No newline at end of file +} diff --git a/src/default_handlers/mod.rs b/src/default_handlers/mod.rs index f693c57..8cc1dc3 100644 --- a/src/default_handlers/mod.rs +++ b/src/default_handlers/mod.rs @@ -1,7 +1,13 @@ -mod integers; -mod floats; mod enums; +mod floats; +mod integers; +mod noop; +mod string; +mod value; -pub use integers::*; +pub use enums::*; pub use floats::*; -pub use enums::*; \ No newline at end of file +pub use integers::*; +pub use noop::*; +pub use string::*; +pub use value::*; diff --git a/src/default_handlers/noop.rs b/src/default_handlers/noop.rs new file mode 100644 index 0000000..1c00efb --- /dev/null +++ b/src/default_handlers/noop.rs @@ -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 IntegerHandler for Handler_Error { + fn handleFixedInteger(&self, _: &mut Runtime, _: &mut Container, _: u64, _: bool) { + _throw(); + } +} + +impl FloatHandler for Handler_Error { + fn handleFloat(&self, _: &mut Runtime, _: &mut Container, _: f64) { + _throw(); + } +} + +impl BooleanHandler for Handler_Error { + fn handleBoolean(&self, _: &mut Runtime, _: &mut Container, _: bool) { + _throw(); + } +} + +impl NullHandler for Handler_Error { + fn handleNull(&self, _: &mut Runtime, _: &mut Container) { + _throw(); + } +} + +/* +impl NoValueHandler for Handler_Error { + fn handleNoValue(&self, _: &mut Runtime, _: &mut Container) { + _throw(); + } +} +*/ + +impl + ObjectHandler for Handler_Error +{ + fn produceObject(&self, _: &mut Runtime) -> ObjectBuilder { + _throw(); + } + + fn storeObject(&self, _: &mut Runtime, _: &mut Container, _: ObjectBuilder) { + _throw(); + } +} + +impl + ArrayHandler for Handler_Error +{ + fn produceArray(&self, _: &mut Runtime) -> ArrayBuilder { + _throw(); + } + + fn storeArray(&self, _: &mut Runtime, _: &mut Container, _: ArrayBuilder) { + _throw(); + } +} + +impl StringHandler + for Handler_Error +{ + fn handleString(&self, _: &mut Runtime, _: &mut Container, _: String) { + _throw(); + } +} + +impl + ObjectConfiguration for Handler_Error +{ + type ObjectBuilder = (); + + #[allow(unreachable_code)] + fn configureObject( + &self, + _: &impl ObjectConfigurationScope, + ) -> impl ObjectHandler { + _throw(); + // return type deducing: + return Handler_Error::default(); + } +} + +impl + ArrayConfiguration for Handler_Error +{ + type ArrayBuilder = (); + + #[allow(unreachable_code)] + fn configureArray( + &self, + _: &impl ArrayConfigurationScope, + ) -> impl ObjectHandler { + _throw(); + // return type deducing: + return Handler_Error::default(); + } +} diff --git a/src/default_handlers/string.rs b/src/default_handlers/string.rs new file mode 100644 index 0000000..7dc5590 --- /dev/null +++ b/src/default_handlers/string.rs @@ -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 + Handler_String +{ + pub fn create(f: StoreFn) -> Self { + return Self { + store: f, + __phantom: PhantomData::default(), + }; + } +} + +impl + StringHandler + for Handler_String +{ + fn handleString(&self, runtime: &mut Runtime, dst: &mut Container, value: String) { + (self.store)(runtime, dst, value); + } +} diff --git a/src/default_handlers/value.rs b/src/default_handlers/value.rs new file mode 100644 index 0000000..d3c7bab --- /dev/null +++ b/src/default_handlers/value.rs @@ -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 + Clone, + HFloat: FloatHandler + Clone, + HBoolean: BooleanHandler + Clone, + HNull: NullHandler + Clone, + HObject: ObjectConfiguration + Clone, + HArray: ArrayConfiguration + Clone, + HString: StringHandler + Clone, +> { + pub int: Option, + pub float: Option, + pub bool: Option, + pub null: Option, + pub object: Option, + pub array: Option, + pub string: Option, + + pub __phantom: PhantomData<(*const Runtime, *const Container, String)>, +} + +impl< + Runtime: ?Sized, + Container: ?Sized, + String, + HInteger: IntegerHandler + Clone, + HFloat: FloatHandler + Clone, + HBoolean: BooleanHandler + Clone, + HNull: NullHandler + Clone, + HObject: ObjectConfiguration + Clone, + HArray: ArrayConfiguration + Clone, + HString: StringHandler + Clone, +> ValueConfiguration + for DefaultValueConfig< + Runtime, + Container, + String, + HInteger, + HFloat, + HBoolean, + HNull, + HObject, + HArray, + HString, + > +{ + fn integerHandler(&self) -> Option> { + return self.int.clone(); + } + + fn floatHandler(&self) -> Option> { + return self.float.clone(); + } + + fn booleanHandler(&self) -> Option> { + return self.bool.clone(); + } + + fn nullHandler(&self) -> Option> { + return self.null.clone(); + } + + fn objectHandler(&self) -> Option> { + return self.object.clone(); + } + + fn arrayHandler(&self) -> Option> { + return self.array.clone(); + } + + fn stringHandler(&self) -> Option> { + return self.string.clone(); + } +} diff --git a/src/dsl.rs b/src/dsl.rs index 854c52b..41dd557 100644 --- a/src/dsl.rs +++ b/src/dsl.rs @@ -1,3 +1,5 @@ +use crate::default_handlers::Handler_Error; + pub trait IntegerHandler: Sized { fn handleFixedInteger( &self, @@ -89,11 +91,31 @@ pub trait ArrayConfigurationScope { } pub trait ValueConfiguration: Sized { - fn integerHandler(&self) -> Option>; - fn floatHandler(&self) -> Option>; - fn booleanHandler(&self) -> Option>; - fn nullHandler(&self) -> Option>; - fn objectHandler(&self) -> Option>; - fn arrayHandler(&self) -> Option>; - fn stringHandler(&self) -> Option>; + fn integerHandler(&self) -> Option> { + return None::; + } + + fn floatHandler(&self) -> Option> { + return None::; + } + + fn booleanHandler(&self) -> Option> { + return None::; + } + + fn nullHandler(&self) -> Option> { + return None::; + } + + fn objectHandler(&self) -> Option> { + return None::; + } + + fn arrayHandler(&self) -> Option> { + return None::; + } + + fn stringHandler(&self) -> Option> { + return None::; + } } diff --git a/src/lib.rs b/src/lib.rs index a1e89db..21b55b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,2 @@ -pub mod dsl; pub mod default_handlers; +pub mod dsl;