salsa/salsa-2022-tests/tracked_fn_on_tracked.rs
Niko Matsakis 4f234cfbb9 remove component and replace with specify option
You can now do `#[salsa::tracked(specify)]` and you will
get a method `some_fn::specify(...)` that can be used to
specify the value.
2022-08-05 02:51:13 -04:00

43 lines
906 B
Rust

//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
#[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 {
field: u32,
}
#[salsa::tracked(jar = Jar)]
fn tracked_fn(db: &dyn Db, input: MyInput) -> MyTracked {
MyTracked::new(db, input.field(db) * 2)
}
#[test]
fn execute() {
#[salsa::db(Jar)]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
impl salsa::Database for Database {
fn salsa_runtime(&self) -> &salsa::Runtime {
self.storage.runtime()
}
}
impl Db for Database {}
let mut db = Database::default();
let input = MyInput::new(&mut db, 22);
assert_eq!(tracked_fn(&db, input).field(&db), 44);
}