From 119d5c35f02178b66bf69aff1087f3348f6cf96a Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 30 Apr 2025 21:49:01 +0300 Subject: [PATCH 1/2] input_dsl: expose InputMap layers; add From for TokenIter --- dsl/src/dsl_iter.rs | 11 ++++++++++- input/src/input_dsl.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dsl/src/dsl_iter.rs b/dsl/src/dsl_iter.rs index de9fe7a..0a94b3c 100644 --- a/dsl/src/dsl_iter.rs +++ b/dsl/src/dsl_iter.rs @@ -14,7 +14,10 @@ use crate::*; /// Provides a native [Iterator] API over the [ConstIntoIter] [SourceIter] /// [TokenIter::next] returns just the [Token] and mutates `self`, /// instead of returning an updated version of the struct as [SourceIter::next] does. -#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct TokenIter<'a>(pub SourceIter<'a>); +#[derive(Copy, Clone, Debug, Default, PartialEq)] pub struct TokenIter<'a>( + pub SourceIter<'a> +); + impl<'a> TokenIter<'a> { pub const fn new (source: &'a str) -> Self { Self(SourceIter::new(source)) @@ -31,6 +34,12 @@ impl<'a> Iterator for TokenIter<'a> { } } +impl<'a> From> for TokenIter<'a> { + fn from (source: SourceIter<'a>) -> Self{ + Self(source) + } +} + /// Owns a reference to the source text. /// [SourceIter::next] emits subsequent pairs of: /// * a [Token] and diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index 3a79fd4..bcc6067 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -74,7 +74,7 @@ impl<'a, S, C: DslCommand<'a, S>, I: DslInput> KeyMap<'a, S, C, I> for TokenIter /// which may be made available subject to given conditions. pub struct InputMap<'a, S, C: DslCommand<'a, S>, I: DslInput, M: KeyMap<'a, S, C, I> + Send + Sync> { __: &'a PhantomData<(S, C, I)>, - layers: Vec<( + pub layers: Vec<( fn(&S)->bool, M )>, From 44ebe17c665b3a65e7a3a0020eff290093fc7ed2 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 30 Apr 2025 21:51:07 +0300 Subject: [PATCH 2/2] input_dsl: cleanup commented code --- input/src/input_dsl.rs | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/input/src/input_dsl.rs b/input/src/input_dsl.rs index bcc6067..1fe3acf 100644 --- a/input/src/input_dsl.rs +++ b/input/src/input_dsl.rs @@ -152,37 +152,3 @@ where None } } - - //fn handle (&self, state: &mut T, input: &U) -> Perhaps { - //for layer in self.layers.iter() { - //if !(layer.0)(state) { - //continue - //} - //let command: Option = SourceIter(layer.1).command::<_, _, _>(state, input); - //if let Some(command) = command { - //if let Some(undo) = command.execute(state)? { - ////app.history.push(undo); - //} - //return Ok(Some(true)) - //} - //} - //Ok(None) - //} -//} - //fn layer (mut self, keymap: &'static str) -> Self { - //self.add_layer(keymap); - //self - //} - //fn layer_if (mut self, condition: impl Fn(&T)->bool + 'static, keymap: &'static str) -> Self { - //self.add_layer_if(condition, keymap); - //self - //} - //fn add_layer (&mut self, keymap: &'static str) -> &mut Self { - //self.layers.push((Box::new(|_|true), keymap)); - //self - //} - //fn add_layer_if (&mut self, condition: impl Fn(&T)->bool + 'static, keymap: &'static str) -> &mut Self { - //self.layers.push((Box::new(condition), keymap)); - //self - //} -//}