From 63eaafbe8fbc9fa074ec38206d5aa1cfdc26cbbc Mon Sep 17 00:00:00 2001 From: Andrew Golovashevich Date: Sun, 7 Dec 2025 17:56:00 +0300 Subject: [PATCH] Strings support and default handlers update --- src/default_handlers/enums.rs | 61 ++++++++++++++++++++++---------- src/default_handlers/floats.rs | 42 +++++++++++++++------- src/default_handlers/integers.rs | 29 +++++++++++---- src/dsl.rs | 32 +++++++++-------- 4 files changed, 113 insertions(+), 51 deletions(-) diff --git a/src/default_handlers/enums.rs b/src/default_handlers/enums.rs index 21704a3..46dbc4c 100644 --- a/src/default_handlers/enums.rs +++ b/src/default_handlers/enums.rs @@ -1,11 +1,18 @@ use crate::dsl::{BooleanHandler, FloatHandler, IntegerHandler, NoValueHandler, NullHandler}; use std::marker::PhantomData; -pub struct Handler_Boolean { +pub struct Handler_Boolean< + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, bool), +> { store: StoreFn, - __phantom: PhantomData, + __phantom: PhantomData<(*const Runtime, *const Container)>, } -impl Handler_Boolean { + +impl + Handler_Boolean +{ pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -13,18 +20,26 @@ impl Handler_Boolean { }; } } -impl BooleanHandler for Handler_Boolean { - fn handleBoolean(&self, dst: &mut S, value: bool) { - (self.store)(dst, value); +impl + BooleanHandler for Handler_Boolean +{ + fn handleBoolean(&self, runtime: &mut Runtime, dst: &mut Container, value: bool) { + (self.store)(runtime, dst, value); } } -pub struct Handler_Null { +pub struct Handler_Null< + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container), +> { store: StoreFn, - __phantom: PhantomData, + __phantom: PhantomData<(*const Runtime, *const Container)>, } -impl Handler_Null { +impl + Handler_Null +{ pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -33,18 +48,26 @@ impl Handler_Null { } } -impl NullHandler for Handler_Null { - fn handleNull(&self, dst: &mut S) { - (self.store)(dst); +impl + NullHandler for Handler_Null +{ + fn handleNull(&self, runtime: &mut Runtime, dst: &mut Container) { + (self.store)(runtime, dst); } } -pub struct Handler_NoValue { +pub struct Handler_NoValue< + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container), +> { store: StoreFn, - __phantom: PhantomData, + __phantom: PhantomData<(*const Runtime, *const Container)>, } -impl Handler_NoValue { +impl + Handler_NoValue +{ pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -53,8 +76,10 @@ impl Handler_NoValue { } } -impl NoValueHandler for Handler_NoValue { - fn handleNoValue(&self, dst: &mut S) { - (self.store)(dst); +impl + NoValueHandler for Handler_NoValue +{ + fn handleNoValue(&self, runtime: &mut Runtime, dst: &mut Container) { + (self.store)(runtime, dst); } } diff --git a/src/default_handlers/floats.rs b/src/default_handlers/floats.rs index 01a8283..312f6b6 100644 --- a/src/default_handlers/floats.rs +++ b/src/default_handlers/floats.rs @@ -1,11 +1,17 @@ use crate::dsl::{FloatHandler, IntegerHandler}; use std::marker::PhantomData; -pub struct Handler_F64 { +pub struct Handler_F64< + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, f64), +> { store: StoreFn, - __phantom: PhantomData, + __phantom: PhantomData<(*const Runtime, *const Container)>, } -impl Handler_F64 { +impl + Handler_F64 +{ pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -13,17 +19,25 @@ impl Handler_F64 { }; } } -impl FloatHandler for Handler_F64 { - fn handleFloat(&self, dst: &mut S, value: f64) { - (self.store)(dst, value); +impl + FloatHandler for Handler_F64 +{ + fn handleFloat(&self, runtime: &mut Runtime, dst: &mut Container, value: f64) { + (self.store)(runtime, dst, value); } } -pub struct Handler_F32 { +pub struct Handler_F32< + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, f32), +> { store: StoreFn, - __phantom: PhantomData, + __phantom: PhantomData<(*const Runtime, *const Container)>, } -impl Handler_F32 { +impl +Handler_F32 +{ pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -31,8 +45,10 @@ impl Handler_F32 { }; } } -impl FloatHandler for Handler_F32 { - fn handleFloat(&self, dst: &mut S, value: f64) { - (self.store)(dst, value as f32); +impl +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/integers.rs b/src/default_handlers/integers.rs index 1418a1d..1ba6e24 100644 --- a/src/default_handlers/integers.rs +++ b/src/default_handlers/integers.rs @@ -3,12 +3,20 @@ use std::marker::PhantomData; macro_rules! defineIntegerHandler { ($vis:vis $name:ident < $int_type:ty >) => { - $vis struct $name { + $vis struct $name < + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, $int_type), + > { store: StoreFn, - __phantom: PhantomData + __phantom: PhantomData<(*const Runtime, *const Container)> } - impl $name { + impl < + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, $int_type), + > $name { pub fn create(f: StoreFn) -> Self { return Self { store: f, @@ -17,11 +25,20 @@ macro_rules! defineIntegerHandler { } } - impl IntegerHandler for $name { - fn handleFixedInteger(&self, dst: &mut S, value: u64, isNegative: bool) { + impl < + Runtime: ?Sized, + Container: ?Sized, + StoreFn: Fn(&mut Runtime, &mut Container, $int_type), + > IntegerHandler for $name { + fn handleFixedInteger( + &self, + runtime: &mut Runtime, dst: &mut Container, + value: u64, isNegative: bool + ) { let downcasted: $int_type; if isNegative { + #[allow(unused_comparisons)] if <$int_type>::MIN >= 0 || value > (<$int_type>::abs_diff(0, <$int_type>::MIN)) as u64 { panic!( "Integer underflow: expected in range {}..={}, got -{}", @@ -39,7 +56,7 @@ macro_rules! defineIntegerHandler { downcasted = value as $int_type; } - (self.store)(dst, downcasted); + (self.store)(runtime, dst, downcasted); return; } } diff --git a/src/dsl.rs b/src/dsl.rs index 750d238..854c52b 100644 --- a/src/dsl.rs +++ b/src/dsl.rs @@ -38,58 +38,62 @@ pub trait ArrayHandler: fn storeArray(&self, runtime: &mut Runtime, dst: &mut ParentContainer, value: ArrayBuilder); } -pub trait ObjectConfiguration: Sized { +pub trait ObjectConfiguration: Sized { type ObjectBuilder: Sized; fn configureObject( &self, - scope: &impl ObjectConfigurationScope, + scope: &impl ObjectConfigurationScope, ) -> impl ObjectHandler; } -pub trait ArrayConfiguration: Sized { +pub trait ArrayConfiguration: Sized { type ArrayBuilder: Sized; fn configureArray( &self, - scope: &impl ArrayConfigurationScope, + scope: &impl ArrayConfigurationScope, ) -> impl ObjectHandler; } -pub trait ObjectConfigurationScope { +pub trait ObjectConfigurationScope { 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); + fn processKey( + &mut self, + name: Self::Key, + config: impl ValueConfiguration, + ); fn processKey_optional( &mut self, name: Self::Key, - config: impl ValueConfiguration, + config: impl ValueConfiguration, fallback: impl NoValueHandler, ); } -pub trait ArrayConfigurationScope { +pub trait ArrayConfigurationScope { fn ignoreElements_required(&self, start: usize, endInclusive: Option); fn ignoreElements_optional(&self, start: usize, endInclusive: Option); fn processElements_required( &self, start: usize, endInclusive: Option, - config: impl ValueConfiguration, + config: impl ValueConfiguration, ); fn processElements_optional( &self, start: usize, endInclusive: Option, - config: impl ValueConfiguration + config: impl ValueConfiguration, ); } -pub trait ValueConfiguration: Sized { +pub trait ValueConfiguration: Sized { fn integerHandler(&self) -> Option>; fn floatHandler(&self) -> Option>; fn booleanHandler(&self) -> Option>; fn nullHandler(&self) -> Option>; - fn arrayHandler(&self) -> Option>; - fn objectHandler(&self) -> Option>; - // fn stringHandler(&self) -> Option>; + fn objectHandler(&self) -> Option>; + fn arrayHandler(&self) -> Option>; + fn stringHandler(&self) -> Option>; }