Skip to content

Commit

Permalink
test: it_composes_from_iter
Browse files Browse the repository at this point in the history
  • Loading branch information
matthunz committed Dec 9, 2024
1 parent 5ae0a51 commit 0854fe9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,32 @@ mod tests {
assert_eq!(x.get(), 2);
}

#[test]
fn it_composes_from_iter() {
#[derive(Data)]
#[actuate(path = "crate")]
struct Wrap {
x: Rc<Cell<i32>>,
}

impl Compose for Wrap {
fn compose(cx: crate::Scope<Self>) -> impl Compose {
compose::from_iter(0..2, move |_| Counter {
x: cx.me().x.clone(),
})
}
}

let x = Rc::new(Cell::new(0));
let mut composer = Composer::new(Wrap { x: x.clone() });

composer.try_compose().unwrap();
assert_eq!(x.get(), 2);

composer.try_compose().unwrap();
assert_eq!(x.get(), 4);
}

#[test]
fn it_composes_memo() {
#[derive(Data)]
Expand Down
4 changes: 3 additions & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
//! ```
use crate::{compose::DynCompose, HashMap};
use core::{error::Error, future::Future, pin::Pin};
use core::{error::Error, future::Future, ops::Range, pin::Pin};

pub use actuate_macros::{data, Data};

Expand Down Expand Up @@ -114,6 +114,8 @@ unsafe impl<T: Data, U: Data> Data for Result<T, U> {}

unsafe impl<T: Data> Data for Pin<T> {}

unsafe impl<T: 'static> Data for Range<T> {}

unsafe impl Data for Box<dyn Error> {}

unsafe impl Data for Box<dyn Future<Output = ()> + '_> {}
Expand Down

0 comments on commit 0854fe9

Please sign in to comment.