mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-11-24 20:20:26 +00:00
39 lines
791 B
Rust
39 lines
791 B
Rust
|
//! Test that a `tracked` fn on a `salsa::input`
|
||
|
//! compiles and executes successfully.
|
||
|
|
||
|
#[salsa::jar(db = Db)]
|
||
|
struct Jar(MyInput, tracked_fn);
|
||
|
|
||
|
trait Db: salsa::DbWithJar<Jar> {}
|
||
|
|
||
|
#[salsa::input(jar = Jar)]
|
||
|
struct MyInput {
|
||
|
field: u32,
|
||
|
}
|
||
|
|
||
|
#[salsa::tracked(jar = Jar)]
|
||
|
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
|
||
|
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), 44);
|
||
|
}
|