mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 13:10:19 +00:00
d6821d1097
This seems like a more consistent abstraction.
47 lines
1.4 KiB
Rust
47 lines
1.4 KiB
Rust
use crate::class_table;
|
|
use crate::compiler::{CompilerQueryContext, Interner};
|
|
use salsa::query_context_storage;
|
|
|
|
#[derive(Default)]
|
|
pub struct QueryContextImpl {
|
|
runtime: salsa::Runtime<QueryContextImpl>,
|
|
storage: QueryContextImplStorage,
|
|
interner: Interner,
|
|
}
|
|
|
|
// This is an example of how you "link up" all the queries in your
|
|
// application.
|
|
query_context_storage! {
|
|
pub struct QueryContextImplStorage for QueryContextImpl {
|
|
impl class_table::ClassTableQueryContext {
|
|
fn all_classes() for class_table::AllClasses;
|
|
fn all_fields() for class_table::AllFields;
|
|
fn fields() for class_table::Fields;
|
|
}
|
|
}
|
|
}
|
|
|
|
// This is an example of how you provide custom bits of stuff that
|
|
// your queries may need; in this case, an `Interner` value.
|
|
impl CompilerQueryContext for QueryContextImpl {
|
|
fn interner(&self) -> &Interner {
|
|
&self.interner
|
|
}
|
|
}
|
|
|
|
// FIXME: This code... probably should not live here. But maybe we
|
|
// just want to provide some helpers or something? I do suspect I want
|
|
// people to be able to customize this.
|
|
//
|
|
// Seems like a classic case where specialization could be useful to
|
|
// permit behavior refinement.
|
|
|
|
impl salsa::QueryContext for QueryContextImpl {
|
|
fn salsa_storage(&self) -> &QueryContextImplStorage {
|
|
&self.storage
|
|
}
|
|
|
|
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
|
&self.runtime
|
|
}
|
|
}
|