mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-11-24 20:20:26 +00:00
46 lines
975 B
Rust
46 lines
975 B
Rust
use test_log::test;
|
|
|
|
#[salsa::jar(db = Db)]
|
|
struct Jar(MyInput, MyTracked<'_>, tracked_fn);
|
|
|
|
trait Db: salsa::DbWithJar<Jar> {}
|
|
|
|
#[salsa::input(jar = Jar)]
|
|
struct MyInput {
|
|
field: u32,
|
|
}
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
struct MyTracked<'db> {
|
|
field: u32,
|
|
}
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
fn tracked_fn<'db>(db: &'db dyn Db, input: MyInput) -> MyTracked<'db> {
|
|
MyTracked::new(db, input.field(db) / 2)
|
|
}
|
|
|
|
#[salsa::db(Jar)]
|
|
#[derive(Default)]
|
|
struct Database {
|
|
storage: salsa::Storage<Self>,
|
|
}
|
|
|
|
impl salsa::Database for Database {}
|
|
|
|
impl Db for Database {}
|
|
|
|
#[test]
|
|
#[should_panic(expected = "access to tracked struct from previous revision")]
|
|
fn execute() {
|
|
let mut db = Database::default();
|
|
|
|
let input = MyInput::new(&db, 22);
|
|
let tracked = tracked_fn(&db, input);
|
|
|
|
// modify the input and change the revision
|
|
input.set_field(&mut db).to(24);
|
|
|
|
// panic when reading fields of tracked structs from older revisions
|
|
tracked.field(&db);
|
|
}
|