salsa/tests/tracked_fn_on_input.rs

36 lines
682 B
Rust
Raw Normal View History

2022-08-05 04:39:00 +00:00
//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
2022-08-05 18:32:12 +00:00
#![allow(warnings)]
2022-08-05 04:39:00 +00:00
#[salsa::jar(db = Db)]
struct Jar(MyInput, tracked_fn);
trait Db: salsa::DbWithJar<Jar> {}
2024-07-16 10:04:01 +00:00
#[salsa::input]
2022-08-05 04:39:00 +00:00
struct MyInput {
field: u32,
}
2024-07-16 10:04:01 +00:00
#[salsa::tracked]
2022-08-05 04:39:00 +00:00
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 {}
2022-08-05 04:39:00 +00:00
impl Db for Database {}
let mut db = Database::default();
let input = MyInput::new(&db, 22);
2022-08-05 04:39:00 +00:00
assert_eq!(tracked_fn(&db, input), 44);
}