2018-10-19 01:19:50 +00:00
|
|
|
use salsa::Database;
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
#[salsa::query_group]
|
|
|
|
trait HelloWorldDatabase: salsa::Database {
|
|
|
|
#[salsa::input]
|
|
|
|
fn input(&self, a: u32, b: u32) -> u32;
|
2018-10-19 01:19:50 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
fn none(&self) -> u32;
|
2018-10-18 23:24:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
fn one(&self, k: u32) -> u32;
|
2018-10-18 23:24:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
fn two(&self, a: u32, b: u32) -> u32;
|
2018-10-18 23:24:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
fn trailing(&self, a: u32, b: u32) -> u32;
|
2018-10-18 23:24:38 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:15:17 +00:00
|
|
|
fn none(_db: &impl HelloWorldDatabase) -> u32 {
|
2018-10-18 23:24:38 +00:00
|
|
|
22
|
|
|
|
}
|
|
|
|
|
|
|
|
fn one(_db: &impl HelloWorldDatabase, k: u32) -> u32 {
|
|
|
|
k * 2
|
|
|
|
}
|
|
|
|
|
2018-10-19 01:15:17 +00:00
|
|
|
fn two(_db: &impl HelloWorldDatabase, a: u32, b: u32) -> u32 {
|
2018-10-18 23:24:38 +00:00
|
|
|
a * b
|
|
|
|
}
|
|
|
|
|
2018-10-19 01:15:17 +00:00
|
|
|
fn trailing(_db: &impl HelloWorldDatabase, a: u32, b: u32) -> u32 {
|
2018-10-18 23:24:38 +00:00
|
|
|
a - b
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct DatabaseStruct {
|
|
|
|
runtime: salsa::Runtime<DatabaseStruct>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::Database for DatabaseStruct {
|
|
|
|
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseStruct> {
|
|
|
|
&self.runtime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::database_storage! {
|
|
|
|
struct DatabaseStorage for DatabaseStruct {
|
|
|
|
impl HelloWorldDatabase {
|
2019-01-12 10:11:59 +00:00
|
|
|
fn input() for InputQuery;
|
|
|
|
fn none() for NoneQuery;
|
|
|
|
fn one() for OneQuery;
|
|
|
|
fn two() for TwoQuery;
|
|
|
|
fn trailing() for TrailingQuery;
|
2018-10-18 23:24:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn execute() {
|
2018-11-01 08:30:54 +00:00
|
|
|
let mut db = DatabaseStruct::default();
|
2018-10-18 23:24:38 +00:00
|
|
|
|
2018-10-19 01:19:50 +00:00
|
|
|
// test what happens with inputs:
|
2019-01-12 10:11:59 +00:00
|
|
|
db.query_mut(InputQuery).set((1, 2), 3);
|
2018-10-19 01:19:50 +00:00
|
|
|
assert_eq!(db.input(1, 2), 3);
|
|
|
|
|
2018-10-18 23:24:38 +00:00
|
|
|
assert_eq!(db.none(), 22);
|
|
|
|
assert_eq!(db.one(11), 22);
|
|
|
|
assert_eq!(db.two(11, 2), 22);
|
|
|
|
assert_eq!(db.trailing(24, 2), 22);
|
|
|
|
}
|