2024-06-18 08:03:53 +00:00
|
|
|
//! Compile Singleton struct test:
|
2022-09-02 12:09:28 +00:00
|
|
|
//!
|
|
|
|
//! Singleton flags are only allowed for input structs. If applied on any other Salsa struct compilation must fail
|
|
|
|
|
2024-06-18 08:03:53 +00:00
|
|
|
mod common;
|
|
|
|
use common::{HasLogger, Logger};
|
2022-09-02 12:09:28 +00:00
|
|
|
|
|
|
|
use test_log::test;
|
|
|
|
|
|
|
|
#[salsa::jar(db = Db)]
|
2024-06-18 08:03:53 +00:00
|
|
|
struct Jar(MyInput, MyTracked, Integers, create_tracked_structs);
|
2022-09-02 12:09:28 +00:00
|
|
|
|
|
|
|
trait Db: salsa::DbWithJar<Jar> + HasLogger {}
|
|
|
|
|
|
|
|
#[salsa::input(singleton)]
|
|
|
|
struct MyInput {
|
|
|
|
field: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked(singleton)]
|
|
|
|
struct MyTracked {
|
|
|
|
field: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked(singleton)]
|
|
|
|
fn create_tracked_structs(db: &dyn Db, input: MyInput) -> Vec<MyTracked> {
|
|
|
|
(0..input.field(db))
|
|
|
|
.map(|i| MyTracked::new(db, i))
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::accumulator(singleton)]
|
|
|
|
struct Integers(u32);
|
|
|
|
|
|
|
|
#[salsa::db(Jar)]
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
|
|
|
storage: salsa::Storage<Self>,
|
|
|
|
logger: Logger,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl salsa::Database for Database {}
|
|
|
|
|
|
|
|
impl Db for Database {}
|
|
|
|
|
|
|
|
impl HasLogger for Database {
|
|
|
|
fn logger(&self) -> &Logger {
|
|
|
|
&self.logger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 08:03:53 +00:00
|
|
|
fn main() {}
|