mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-11-24 12:16:25 +00:00
36 lines
763 B
Rust
36 lines
763 B
Rust
#![allow(warnings)]
|
|
|
|
use salsa::plumbing::HasStorage;
|
|
use salsa::{Database, Durability, Setter};
|
|
|
|
mod common;
|
|
#[salsa::input]
|
|
struct MyInput {
|
|
field: u32,
|
|
}
|
|
|
|
#[salsa::tracked]
|
|
fn tracked_fn(db: &dyn salsa::Database, input: MyInput) -> u32 {
|
|
input.field(db) * 2
|
|
}
|
|
|
|
#[test]
|
|
fn execute() {
|
|
let mut db = salsa::DatabaseImpl::default();
|
|
|
|
let input_high = MyInput::new(&mut db, 0);
|
|
input_high
|
|
.set_field(&mut db)
|
|
.with_durability(Durability::HIGH)
|
|
.to(2200);
|
|
|
|
assert_eq!(tracked_fn(&db, input_high), 4400);
|
|
|
|
// Changing the value should re-execute the query
|
|
input_high
|
|
.set_field(&mut db)
|
|
.with_durability(Durability::HIGH)
|
|
.to(2201);
|
|
|
|
assert_eq!(tracked_fn(&db, input_high), 4402);
|
|
}
|