pddl/types/
time_specifier.rs1use std::fmt::{Display, Formatter};
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq)]
10pub enum TimeSpecifier {
11 Start,
13 End,
15}
16
17pub mod names {
18 pub const START: &str = "start";
19 pub const END: &str = "end";
20}
21
22impl Display for TimeSpecifier {
23 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
24 match self {
25 TimeSpecifier::Start => write!(f, "{}", names::START),
26 TimeSpecifier::End => write!(f, "{}", names::END),
27 }
28 }
29}
30
31impl TryFrom<&str> for TimeSpecifier {
32 type Error = ParseError;
33
34 fn try_from(value: &str) -> Result<Self, Self::Error> {
35 match value {
36 names::START => Ok(Self::Start),
37 names::END => Ok(Self::End),
38 _ => Err(ParseError::InvalidSpecifier),
39 }
40 }
41}
42
43#[derive(Debug, Clone, thiserror::Error)]
44pub enum ParseError {
45 #[error("Invalid specifier")]
46 InvalidSpecifier,
47}