2022-08-03 04:30:52 +00:00
|
|
|
use crate::{
|
|
|
|
cycle::CycleRecoveryStrategy,
|
2022-08-03 12:51:14 +00:00
|
|
|
ingredient::Ingredient,
|
2022-08-03 04:30:52 +00:00
|
|
|
key::{DatabaseKeyIndex, DependencyIndex},
|
2022-08-11 04:28:34 +00:00
|
|
|
runtime::{local_state::QueryEdges, Runtime},
|
2022-08-03 04:30:52 +00:00
|
|
|
AsId, IngredientIndex, Revision,
|
|
|
|
};
|
2022-08-01 10:54:21 +00:00
|
|
|
|
2022-08-03 04:30:52 +00:00
|
|
|
pub trait InputId: AsId {}
|
|
|
|
impl<T: AsId> InputId for T {}
|
|
|
|
|
|
|
|
pub struct InputIngredient<Id>
|
|
|
|
where
|
|
|
|
Id: InputId,
|
|
|
|
{
|
|
|
|
ingredient_index: IngredientIndex,
|
|
|
|
counter: u32,
|
|
|
|
_phantom: std::marker::PhantomData<Id>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Id> InputIngredient<Id>
|
|
|
|
where
|
|
|
|
Id: InputId,
|
|
|
|
{
|
|
|
|
pub fn new(index: IngredientIndex) -> Self {
|
|
|
|
Self {
|
|
|
|
ingredient_index: index,
|
|
|
|
counter: Default::default(),
|
|
|
|
_phantom: std::marker::PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn database_key_index(&self, id: Id) -> DatabaseKeyIndex {
|
|
|
|
DatabaseKeyIndex {
|
|
|
|
ingredient_index: self.ingredient_index,
|
|
|
|
key_index: id.as_id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-03 12:51:14 +00:00
|
|
|
pub fn new_input(&mut self, _runtime: &mut Runtime) -> Id {
|
2022-08-03 04:30:52 +00:00
|
|
|
let next_id = self.counter;
|
|
|
|
self.counter += 1;
|
2022-08-08 04:06:46 +00:00
|
|
|
Id::from_id(crate::Id::from_u32(next_id))
|
2022-08-03 04:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<DB: ?Sized, Id> Ingredient<DB> for InputIngredient<Id>
|
|
|
|
where
|
|
|
|
Id: InputId,
|
|
|
|
{
|
2022-08-03 12:51:14 +00:00
|
|
|
fn maybe_changed_after(&self, _db: &DB, _input: DependencyIndex, _revision: Revision) -> bool {
|
2022-08-03 04:30:52 +00:00
|
|
|
// Input ingredients are just a counter, they store no data, they are immortal.
|
|
|
|
// Their *fields* are stored in function ingredients elsewhere.
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy {
|
|
|
|
CycleRecoveryStrategy::Panic
|
|
|
|
}
|
|
|
|
|
2022-08-11 04:28:34 +00:00
|
|
|
fn inputs(&self, _key_index: crate::Id) -> Option<QueryEdges> {
|
2022-08-03 04:30:52 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|