mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
iterator being const when not needed
This commit is contained in:
parent
67148a4aa4
commit
a595e2e895
4 changed files with 36 additions and 46 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::*;
|
||||
pub trait TryFromAtom<'a, T>: Sized {
|
||||
fn try_from_atom (state: &'a T, value: Value<'a>) -> Option<Self> {
|
||||
if let Value::Exp(0, iter) = value { return Self::try_from_expr(state, iter) }
|
||||
if let Exp(0, iter) = value { return Self::try_from_expr(state, iter) }
|
||||
None
|
||||
}
|
||||
fn try_from_expr (_state: &'a T, _iter: TokenIter<'a>) -> Option<Self> {
|
||||
|
|
@ -43,10 +43,8 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
impl Context<$type> for $State {
|
||||
#[allow(unreachable_code)]
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
_ => return None
|
||||
})
|
||||
use Value::*;
|
||||
Some(match atom { $(Sym($pat) => $expr,)* _ => return None })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -55,10 +53,8 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
impl<$lt> Context<$lt, $type> for $State {
|
||||
#[allow(unreachable_code)]
|
||||
fn get (&$lt $self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
_ => return None
|
||||
})
|
||||
use Value::*;
|
||||
Some(match atom { $(Sym($pat) => $expr,)* _ => return None })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -71,11 +67,8 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<$T: $Trait> Context<$type> for $T {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
Value::Num(n) => *n as $type,
|
||||
_ => return None
|
||||
})
|
||||
use Value::*;
|
||||
Some(match atom { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -83,11 +76,8 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl Context<$type> for $State {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
Some(match atom {
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
Value::Num(n) => *n as $type,
|
||||
_ => return None
|
||||
})
|
||||
use Value::*;
|
||||
Some(match atom { $(Sym($pat) => $expr,)* Num(n) => *n as $type, _ => return None })
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -100,11 +90,12 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
($type:ty:|$self:ident:<$T:ident:$Trait:path>|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl<$T: $Trait> Context<$type> for $T {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
use Value::*;
|
||||
Some(match atom {
|
||||
Value::Num(n) => match *n { 0 => false, _ => true },
|
||||
Value::Sym(":false") | Value::Sym(":f") => false,
|
||||
Value::Sym(":true") | Value::Sym(":t") => true,
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
Num(n) => match *n { 0 => false, _ => true },
|
||||
Sym(":false") | Sym(":f") => false,
|
||||
Sym(":true") | Sym(":t") => true,
|
||||
$(Sym($pat) => $expr,)*
|
||||
_ => return Context::get(self, atom)
|
||||
})
|
||||
}
|
||||
|
|
@ -114,11 +105,12 @@ impl<T: Context<U>, U> Context<U> for Option<T> {
|
|||
($type:ty:|$self:ident:$State:ty|{ $($pat:pat => $expr:expr),* $(,)? }) => {
|
||||
impl Context<$type> for $State {
|
||||
fn get (&$self, atom: &Value) -> Option<$type> {
|
||||
use Value::*;
|
||||
Some(match atom {
|
||||
Value::Num(n) => match *n { 0 => false, _ => true },
|
||||
Value::Sym(":false") | Value::Sym(":f") => false,
|
||||
Value::Sym(":true") | Value::Sym(":t") => true,
|
||||
$(Value::Sym($pat) => $expr,)*
|
||||
Num(n) => match *n { 0 => false, _ => true },
|
||||
Sym(":false") | Sym(":f") => false,
|
||||
Sym(":true") | Sym(":t") => true,
|
||||
$(Sym($pat) => $expr,)*
|
||||
_ => return None
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue