1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use serde::{Deserialize, Serialize};

/// A type definition.
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TypeDef {
    /// The name of the type.
    pub name: String,
    /// The parent type. If not specified, the parent type is `object`.
    pub parent: Option<String>,
}

impl TypeDef {
    /// Convert the type definition to PDDL.
    pub fn to_pddl(&self) -> String {
        self.parent
            .as_ref()
            .map_or_else(|| self.name.clone(), |parent| format!("{} - {}", self.name, parent))
    }
}