refactor: remove Axis::Unassigned; axis_of returns Option<Axis>
Axis::Unassigned served two purposes that Option already covers:
1. "this category has no assignment yet" → None
2. "this category doesn't exist" → None
By removing the variant and changing axis_of to return Option<Axis>,
callers are forced by the compiler to handle the absent-category case
explicitly (via match or unwrap_or), rather than silently treating it
like a real axis value.
SetAxis { axis: String } also upgraded to SetAxis { axis: Axis }.
Previously, constructing SetAxis with an invalid string (e.g. "diagonal")
would compile and then silently fail at dispatch. Now the type only admits
valid axis values; the dispatch string-parser is gone.
Axis gains #[serde(rename_all = "lowercase")] so existing JSON command
files (smoke.jsonl, etc.) using "row"/"column"/"page" continue to work.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
use crate::model::Model;
|
||||
use crate::model::cell::{CellKey, CellValue};
|
||||
use crate::formula::parse_formula;
|
||||
use crate::view::Axis;
|
||||
use crate::persistence;
|
||||
use crate::import::analyzer::{analyze_records, extract_array_at_path, FieldKind};
|
||||
use super::types::{CellValueArg, Command, CommandResult};
|
||||
@ -105,14 +104,8 @@ pub fn dispatch(model: &mut Model, cmd: &Command) -> CommandResult {
|
||||
}
|
||||
|
||||
Command::SetAxis { category, axis } => {
|
||||
let ax = match axis.to_lowercase().as_str() {
|
||||
"row" | "rows" => Axis::Row,
|
||||
"column" | "col" | "columns" => Axis::Column,
|
||||
"page" | "pages" | "filter" => Axis::Page,
|
||||
other => return CommandResult::err(format!("Unknown axis '{other}'")),
|
||||
};
|
||||
match model.active_view_mut() {
|
||||
Some(view) => { view.set_axis(category, ax); CommandResult::ok() }
|
||||
Some(view) => { view.set_axis(category, *axis); CommandResult::ok() }
|
||||
None => CommandResult::err("No active view"),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use crate::view::Axis;
|
||||
|
||||
/// All commands that can mutate a Model.
|
||||
///
|
||||
@ -44,8 +45,7 @@ pub enum Command {
|
||||
SwitchView { name: String },
|
||||
|
||||
/// Set the axis of a category in the active view.
|
||||
/// axis: "row" | "column" | "page"
|
||||
SetAxis { category: String, axis: String },
|
||||
SetAxis { category: String, axis: Axis },
|
||||
|
||||
/// Set the page-axis selection for a category.
|
||||
SetPageSelection { category: String, item: String },
|
||||
|
||||
Reference in New Issue
Block a user