salsa/tests/tracked_fn_on_tracked.rs

34 lines
635 B
Rust
Raw Normal View History

2022-08-05 04:41:00 +00:00
//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
2024-07-16 10:04:01 +00:00
#[salsa::input]
2022-08-05 04:41:00 +00:00
struct MyInput {
field: u32,
}
2024-07-16 10:04:01 +00:00
#[salsa::tracked]
2024-05-24 01:16:30 +00:00
struct MyTracked<'db> {
2022-08-05 04:41:00 +00:00
field: u32,
}
2024-07-16 10:04:01 +00:00
#[salsa::tracked]
2024-07-19 13:13:48 +00:00
fn tracked_fn(db: &dyn salsa::Database, input: MyInput) -> MyTracked<'_> {
2022-08-05 04:41:00 +00:00
MyTracked::new(db, input.field(db) * 2)
}
2024-07-17 10:41:56 +00:00
#[salsa::db]
2022-08-06 06:26:22 +00:00
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
2022-08-05 04:41:00 +00:00
2024-07-17 10:41:56 +00:00
#[salsa::db]
impl salsa::Database for Database {}
2022-08-05 04:41:00 +00:00
2022-08-06 06:26:22 +00:00
#[test]
fn execute() {
let db = Database::default();
let input = MyInput::new(&db, 22);
2022-08-05 04:41:00 +00:00
assert_eq!(tracked_fn(&db, input).field(&db), 44);
}