2024-07-17 12:50:04 +00:00
|
|
|
use salsa::{Database as Db, Setter};
|
2024-04-05 09:14:45 +00:00
|
|
|
use test_log::test;
|
|
|
|
|
2024-07-16 10:04:01 +00:00
|
|
|
#[salsa::input]
|
2024-04-05 09:14:45 +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> {
|
2024-04-05 09:14:45 +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 Db, input: MyInput) -> MyTracked<'_> {
|
2024-04-05 09:14:45 +00:00
|
|
|
MyTracked::new(db, input.field(db) / 2)
|
|
|
|
}
|
|
|
|
|
2024-07-17 12:50:04 +00:00
|
|
|
#[salsa::db]
|
2024-04-05 09:14:45 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
|
|
|
storage: salsa::Storage<Self>,
|
|
|
|
}
|
|
|
|
|
2024-07-17 12:50:04 +00:00
|
|
|
#[salsa::db]
|
2024-04-05 09:14:45 +00:00
|
|
|
impl salsa::Database for Database {}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn execute() {
|
|
|
|
let mut db = Database::default();
|
|
|
|
|
|
|
|
let input1 = MyInput::new(&db, 22);
|
|
|
|
let input2 = MyInput::new(&db, 44);
|
|
|
|
let _tracked1 = tracked_fn(&db, input1);
|
|
|
|
let _tracked2 = tracked_fn(&db, input2);
|
|
|
|
|
|
|
|
// modify the input and change the revision
|
|
|
|
input1.set_field(&mut db).to(24);
|
|
|
|
let tracked2 = tracked_fn(&db, input2);
|
|
|
|
|
2024-04-05 09:16:50 +00:00
|
|
|
// this should not panic
|
2024-04-05 09:14:45 +00:00
|
|
|
tracked2.field(&db);
|
|
|
|
}
|