2022-08-05 04:41:00 +00:00
|
|
|
//! Test that a `tracked` fn on a `salsa::input`
|
|
|
|
//! compiles and executes successfully.
|
|
|
|
|
|
|
|
#[salsa::jar(db = Db)]
|
2022-08-05 06:46:16 +00:00
|
|
|
struct Jar(MyInput, MyTracked, tracked_fn);
|
2022-08-05 04:41:00 +00:00
|
|
|
|
|
|
|
trait Db: salsa::DbWithJar<Jar> {}
|
|
|
|
|
|
|
|
#[salsa::input(jar = Jar)]
|
|
|
|
struct MyInput {
|
|
|
|
field: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
|
|
struct MyTracked {
|
|
|
|
field: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
|
|
fn tracked_fn(db: &dyn Db, input: MyInput) -> MyTracked {
|
|
|
|
MyTracked::new(db, input.field(db) * 2)
|
|
|
|
}
|
|
|
|
|
2022-08-06 06:26:22 +00:00
|
|
|
#[salsa::db(Jar)]
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
|
|
|
storage: salsa::Storage<Self>,
|
|
|
|
}
|
2022-08-05 04:41:00 +00:00
|
|
|
|
2022-08-24 12:11:48 +00:00
|
|
|
impl salsa::Database for Database {}
|
2022-08-05 04:41:00 +00:00
|
|
|
|
2022-08-06 06:26:22 +00:00
|
|
|
impl Db for Database {}
|
2022-08-05 04:41:00 +00:00
|
|
|
|
2022-08-06 06:26:22 +00:00
|
|
|
#[test]
|
|
|
|
fn execute() {
|
2022-09-03 21:48:24 +00:00
|
|
|
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);
|
|
|
|
}
|