iterator being const when not needed

This commit is contained in:
🪞👃🪞 2025-01-18 23:58:18 +01:00
parent 67148a4aa4
commit a595e2e895
4 changed files with 36 additions and 46 deletions

View file

@ -32,7 +32,6 @@ impl<E: Output, A: Content<E>, B: Content<E>> Content<E> for Bsp<A, B> {
}
}
try_from_expr!(<'a, E>: Bsp<RenderBox<'a, E>, RenderBox<'a, E>>: |state, iter| {
panic!("bsp:\n{iter:#?}\n{:#?}", iter.peek());
if let Some(Token { value: Value::Key(key), .. }) = iter.peek() {
let iter = iter.clone().next().unwrap().1;
match key {

View file

@ -7,7 +7,7 @@ pub struct Either<A, B>(pub bool, pub A, pub B);
impl<A, B> Either<A, B> { pub fn new (c: bool, a: A, b: B) -> Self { Self(c, a, b) } }
try_from_expr!(<'a, E>: When<RenderBox<'a, E>>: |state, iter| {
if let Some(Token { value: Value::Key("when"), .. }) = iter.peek() {
let iter = iter.clone();
let iter = iter.clone().next().unwrap().1;
let condition = iter.next();
if let Some((ref condition, _)) = condition {
let condition = state.get(&condition.value).expect("no condition");
@ -20,7 +20,7 @@ try_from_expr!(<'a, E>: When<RenderBox<'a, E>>: |state, iter| {
});
try_from_expr!(<'a, E>: Either<RenderBox<'a, E>, RenderBox<'a, E>>: |state, iter| {
if let Some((Token { value: Value::Key("either"), .. }, _)) = iter.next() {
let iter = iter.clone();
let iter = iter.clone().next().unwrap().1;
let condition = iter.next();
if let Some((ref condition, _)) = condition {
let condition = state.get(&condition.value).expect("no condition");

View file

@ -1,9 +1,6 @@
use crate::*;
/// Defines an enum that transforms its content
/// along either the X axis, the Y axis, or both.
///
/// The `_Unused` variant wraps the `Output` type
/// using `PhantomData` to permit the double generic.
macro_rules! transform_xy {
($x:literal $y:literal $xy:literal |$self:ident : $Enum:ident, $to:ident|$area:expr) => {
pub enum $Enum<T> { X(T), Y(T), XY(T) }
@ -15,11 +12,12 @@ macro_rules! transform_xy {
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T>
for $Enum<RenderBox<'a, E>> {
fn try_from_expr (state: &'a T, iter: TokenIter<'a>) -> Option<Self> {
Some(if let Some((Token { value: Value::Key($x), .. }, _)) = iter.next() {
let iter = iter.clone();
Some(if let Some((Token { value: Value::Key($x), .. }, iter)) = iter.next() {
Self::x(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else if let Some((Token { value: Value::Key($y), .. }, _)) = iter.next() {
} else if let Some((Token { value: Value::Key($y), .. }, iter)) = iter.next() {
Self::y(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else if let Some((Token { value: Value::Key($xy), .. }, _)) = iter.next() {
} else if let Some((Token { value: Value::Key($xy), .. }, iter)) = iter.next() {
Self::xy(state.get_content(&iter.next().expect("no content").0.value).expect("no content"))
} else {
return None
@ -41,6 +39,7 @@ macro_rules! transform_xy {
}
}
}
/// Defines an enum that parametrically transforms its content
/// along either the X axis, the Y axis, or both.
macro_rules! transform_xy_unit {
@ -54,18 +53,18 @@ macro_rules! transform_xy_unit {
impl<'a, E: Output + 'a, T: ViewContext<'a, E>> TryFromAtom<'a, T>
for $Enum<E::Unit, RenderBox<'a, E>> {
fn try_from_expr (state: &'a T, iter: TokenIter<'a>) -> Option<Self> {
Some(if let Some((Token { value: Value::Key($x), .. }, _)) = iter.next() {
let x = state.get(&iter.next().expect("no x").0.value).expect("no x");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
Some(if let Some((Token { value: Value::Key($x), .. }, iter)) = iter.next() {
let (x, iter) = iter.next().map(|(x, iter)|(state.get(&x.value).expect("no x provided"), iter)).expect("no x specified");
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
Self::x(x, c)
} else if let Some((Token { value: Value::Key($y), .. }, _)) = iter.next() {
let y = state.get(&iter.next().expect("no y").0.value).expect("no y");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
} else if let Some((Token { value: Value::Key($y), .. }, iter)) = iter.next() {
let (y, iter) = iter.next().map(|(y, iter)|(state.get(&y.value).expect("no y provided"), iter)).expect("no y specified");
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
Self::y(y, c)
} else if let Some((Token { value: Value::Key($xy), .. }, _)) = iter.next() {
let x = state.get(&iter.next().expect("no x").0.value).expect("no x");
let y = state.get(&iter.next().expect("no y").0.value).expect("no y");
let c = state.get_content(&iter.next().expect("no content").0.value).expect("no content");
} else if let Some((Token { value: Value::Key($xy), .. }, iter)) = iter.next() {
let (x, iter) = iter.next().map(|(x, iter)|(state.get(&x.value).expect("no x provided"), iter)).expect("no x specified");
let (y, iter) = iter.next().map(|(y, iter)|(state.get(&y.value).expect("no y provided"), iter)).expect("no y specified");
let (c, _) = iter.next().map(|(x, iter)|(state.get_content(&x.value).expect("no content provided"), iter)).expect("no content specified");
Self::xy(x, y, c)
} else {
return None