rl_model/model/
state.rs

1use super::*;
2use crate::parser::Position;
3
4#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, Default)]
5pub struct StateId(pub ResourceId, pub usize);
6impl Id for StateId {
7    fn index(&self) -> usize {
8        self.1
9    }
10}
11impl StateId {
12    pub fn resource(&self) -> ResourceId {
13        self.0
14    }
15}
16
17#[derive(Debug, Clone)]
18pub struct State {
19    id: StateId,
20    name: String,
21    position: Option<Position>,
22}
23
24impl State {
25    pub fn new<S: Into<String>>(name: S, position: Option<Position>) -> Self {
26        let id = StateId::default();
27        let name = name.into();
28        Self { id, name, position }
29    }
30}
31
32impl Named<StateId> for State {
33    fn id(&self) -> StateId {
34        self.id
35    }
36    fn set_id(&mut self, id: StateId) {
37        self.id = id;
38    }
39    fn name(&self) -> &str {
40        &self.name
41    }
42    fn position(&self) -> Option<Position> {
43        self.position.clone()
44    }
45}
46
47impl std::fmt::Display for State {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        write!(f, "{}", self.name)
50    }
51}