pddl/types/
assign_op_t.rs

1//! Contains the timed effect assignment operation type [`AssignOpT`].
2
3use std::fmt::{Display, Formatter};
4
5/// An assignment operation.
6///
7/// ## Usage
8/// Used by [`TimedEffect`](crate::TimedEffect).
9#[derive(Debug, Copy, Clone, Eq, PartialEq)]
10pub enum AssignOpT {
11    Increase,
12    Decrease,
13}
14
15pub mod names {
16    pub const INCREASE: &str = "increase";
17    pub const DECREASE: &str = "decrease";
18}
19
20impl Display for AssignOpT {
21    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
22        match self {
23            AssignOpT::Increase => write!(f, "{}", names::INCREASE),
24            AssignOpT::Decrease => write!(f, "{}", names::DECREASE),
25        }
26    }
27}
28
29impl TryFrom<&str> for AssignOpT {
30    type Error = ParseError;
31
32    fn try_from(value: &str) -> Result<Self, Self::Error> {
33        match value {
34            names::INCREASE => Ok(Self::Increase),
35            names::DECREASE => Ok(Self::Decrease),
36            _ => Err(ParseError::InvalidOperation),
37        }
38    }
39}
40
41#[derive(Debug, Clone, thiserror::Error)]
42pub enum ParseError {
43    #[error("Invalid operation")]
44    InvalidOperation,
45}