remove View; allow rendering Result
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-05-19 02:23:26 +03:00
parent 90f5699fff
commit f08593f0f8
5 changed files with 64 additions and 89 deletions

View file

@ -16,19 +16,35 @@ use crate::*;
/// Maps a sequencer of EDN tokens to parameters of supported types
/// for a given context.
pub trait Dsl<U>: Sized {
fn take <'state, 'source> (
&'state self,
_: &mut TokenIter<'source>
) -> Perhaps<U> {
pub trait Dsl<Value>: Sized {
fn take <'state, 'source> (&'state self, _: &mut TokenIter<'source>) -> Perhaps<Value> {
unimplemented!()
}
fn take_or_fail <'state, 'source> (
&'state self,
token: &mut TokenIter<'source>,
error: impl Into<Box<dyn std::error::Error>>
) -> Usually<U> {
if let Some(value) = Dsl::<U>::take(self, token)? {
) -> Usually<Value> {
if let Some(value) = Dsl::<Value>::take(self, token)? {
Ok(value)
} else {
Result::Err(error.into())
}
}
}
pub trait FromDsl<'state, State>: Sized {
fn take_from <'source: 'state> (state: &'state State, _token: &mut TokenIter<'source>)
-> Perhaps<Self>
{
unimplemented!()
}
fn take_from_or_fail <'source: 'state> (
state: &'state State,
token: &mut TokenIter<'source>,
error: impl Into<Box<dyn std::error::Error>>
) -> Usually<Self> {
if let Some(value) = FromDsl::<State>::take_from(state, token)? {
Ok(value)
} else {
Result::Err(error.into())
@ -53,23 +69,3 @@ impl<'state, X, Y> Dsl<X> for Y where Y: FromDsl<'state, X> {
//impl<T, U: FromDsl<T>> Dsl<U> for T {
//}
pub trait FromDsl<'state, T>: Sized {
fn take_from <'source: 'state> (
state: &'state T,
_token: &mut TokenIter<'source>
) -> Perhaps<Self> {
unimplemented!()
}
fn take_from_or_fail <'source: 'state> (
state: &'state T,
token: &mut TokenIter<'source>,
error: impl Into<Box<dyn std::error::Error>>
) -> Usually<Self> {
if let Some(value) = FromDsl::<T>::take_from(state, token)? {
Ok(value)
} else {
Result::Err(error.into())
}
}
}