mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-28 02:47:17 +00:00
30 lines
857 B
Rust
30 lines
857 B
Rust
use std::fmt;
|
|||
|
|
|
||
|
|
use crate::State;
|
||
|
|
|
||
|
|
/// The effect of a command on the engine state.
|
||
|
|
///
|
||
|
|
/// Each command is a small struct holding its arguments, with its effect implemented in its
|
||
|
|
/// own file. Effects are built from the reusable patterns in `pattern/`.
|
||
|
|
pub trait Apply {
|
||
|
|
fn apply(self, state: &mut State) -> Result<(), CommandError>;
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||
|
|
pub enum CommandError {
|
||
|
|
/// The command would not change anything.
|
||
|
|
NothingToDo,
|
||
|
|
/// The input data could not be parsed.
|
||
|
|
InvalidData(String),
|
||
|
|
}
|
||
|
|
|
||
|
|
impl fmt::Display for CommandError {
|
||
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||
|
|
match self {
|
||
|
|
Self::NothingToDo => write!(f, "nothing to do"),
|
||
|
|
Self::InvalidData(err) => write!(f, "invalid data: {err}"),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl std::error::Error for CommandError {}
|