proc: auto implement Context on command target

Context and TryFromDsl overlap
This commit is contained in:
🪞👃🪞 2025-05-09 21:13:46 +03:00
parent 3bb38f2d27
commit 20ccff13de
5 changed files with 17 additions and 13 deletions

View file

@ -18,24 +18,20 @@ pub type ParseResult<T> = Result<T, ParseError>;
pub trait TryFromDsl<'state, T>: Sized {
fn try_from_expr <'source: 'state> (
_state: &'state T, _iter: TokenIter<'source>
_state: &'state T, _iter: &mut TokenIter<'source>
) -> Option<Self> {
None
}
fn try_from_atom <'source: 'state> (
state: &'state T, value: Value<'source>
) -> Option<Self> {
if let Exp(0, iter) = value {
return Self::try_from_expr(state, iter.clone())
if let Exp(0, mut iter) = value {
return Self::try_from_expr(state, &mut iter)
}
None
}
}
pub trait TryIntoDsl<T>: Sized {
fn try_into_atom (&self) -> Option<Value>;
}
/// Map EDN tokens to parameters of a given type for a given context
pub trait Context<'state, U>: Sized {
fn get <'source> (&'state self, _iter: &mut TokenIter<'source>) -> Option<U> {