refactor: make active_view and axis_of infallible
Both functions previously returned Option despite their invariants guaranteeing a value: active_view always names an existing view (maintained by new/switch_view/delete_view), and axis_of only returns None for categories never registered with the view (a programming error). Callers no longer need to handle the impossible None case, eliminating ~15 match/if-let Option guards across app.rs, dispatch.rs, grid.rs, tile_bar.rs, and category_panel.rs. Also adds Model::evaluate_f64 (returns 0.0 for empty cells) and collapses the double match-on-axis pattern in tile_bar/category_panel into a single axis_display(Axis) helper. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -9,6 +9,14 @@ use crate::model::Model;
|
||||
use crate::view::Axis;
|
||||
use crate::ui::app::AppMode;
|
||||
|
||||
fn axis_display(axis: Axis) -> (&'static str, Color) {
|
||||
match axis {
|
||||
Axis::Row => ("Row ↕", Color::Green),
|
||||
Axis::Column => ("Col ↔", Color::Blue),
|
||||
Axis::Page => ("Page ☰", Color::Magenta),
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CategoryPanel<'a> {
|
||||
pub model: &'a Model,
|
||||
pub mode: &'a AppMode,
|
||||
@ -44,10 +52,7 @@ impl<'a> Widget for CategoryPanel<'a> {
|
||||
let inner = block.inner(area);
|
||||
block.render(area, buf);
|
||||
|
||||
let view = match self.model.active_view() {
|
||||
Some(v) => v,
|
||||
None => return,
|
||||
};
|
||||
let view = self.model.active_view();
|
||||
|
||||
let cat_names: Vec<&str> = self.model.category_names();
|
||||
if cat_names.is_empty() {
|
||||
@ -65,19 +70,7 @@ impl<'a> Widget for CategoryPanel<'a> {
|
||||
if i as u16 >= list_height { break; }
|
||||
let y = inner.y + i as u16;
|
||||
|
||||
let axis = view.axis_of(cat_name);
|
||||
let axis_str = match axis {
|
||||
Some(Axis::Row) => "Row ↕",
|
||||
Some(Axis::Column) => "Col ↔",
|
||||
Some(Axis::Page) => "Page ☰",
|
||||
None => "none",
|
||||
};
|
||||
let axis_color = match axis {
|
||||
Some(Axis::Row) => Color::Green,
|
||||
Some(Axis::Column) => Color::Blue,
|
||||
Some(Axis::Page) => Color::Magenta,
|
||||
None => Color::DarkGray,
|
||||
};
|
||||
let (axis_str, axis_color) = axis_display(view.axis_of(cat_name));
|
||||
|
||||
let item_count = self.model.category(cat_name).map(|c| c.items.len()).unwrap_or(0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user