refactor: make Model::formulas private, expose read-only accessor
Previously `pub formulas: Vec<Formula>` allowed any code to call `model.formulas.push(formula)` directly, bypassing the dedup logic in `add_formula` that enforces the (target, target_category) uniqueness invariant. Making the field private means the only mutation paths are `add_formula` and `remove_formula`, both of which maintain the invariant. A `pub fn formulas(&self) -> &[Formula]` accessor preserves read access for the UI and tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -14,7 +14,7 @@ pub struct Model {
|
||||
pub name: String,
|
||||
pub categories: IndexMap<String, Category>,
|
||||
pub data: DataStore,
|
||||
pub formulas: Vec<Formula>,
|
||||
formulas: Vec<Formula>,
|
||||
pub views: IndexMap<String, View>,
|
||||
pub active_view: String,
|
||||
next_category_id: CategoryId,
|
||||
@ -86,6 +86,10 @@ impl Model {
|
||||
self.formulas.retain(|f| !(f.target == target && f.target_category == target_category));
|
||||
}
|
||||
|
||||
pub fn formulas(&self) -> &[Formula] {
|
||||
&self.formulas
|
||||
}
|
||||
|
||||
pub fn active_view(&self) -> Option<&View> {
|
||||
self.views.get(&self.active_view)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user