1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::{Map,MapStateInitialized};
use crate::devices::TrainController;
use crate::states::{ReferenceStateInitialized, ReferenceState, ReferenceStateUninitialized};
use common_infrastructure::devices::Train;
use serde::{Deserialize, Serialize};
use std::ops::Deref;
pub trait TrainRef: ReferenceState {}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Copy, Clone)]
pub struct UnIntiTrainRef{
pub train: Train
}
impl TrainRef for UnIntiTrainRef{}
impl ReferenceStateUninitialized for UnIntiTrainRef{
fn initialize(self, map: & Map<MapStateInitialized>) -> Self::InitializedType {
let train = map.get_train(self.train).unwrap();
IntiTrainRef{
train
}
}
}
impl ReferenceState for UnIntiTrainRef{
type InitializedType = IntiTrainRef;
type UninitializedType = Self;
}
impl From<Train> for UnIntiTrainRef{
fn from(value: Train) -> Self {
UnIntiTrainRef{
train: value
}
}
}
#[derive(Debug,Clone,PartialEq,Eq)]
pub struct IntiTrainRef{
pub train: *const TrainController<MapStateInitialized>
}
impl TrainRef for IntiTrainRef{}
impl Deref for IntiTrainRef{
type Target = TrainController<MapStateInitialized>;
fn deref(&self) -> &Self::Target {
unsafe {&*self.train}
}
}
impl ReferenceStateInitialized for IntiTrainRef{
fn un_initialize(self) -> Self::UninitializedType {
UnIntiTrainRef{
train: unsafe{(*self.train).train}
}
}
}
impl ReferenceState for IntiTrainRef{
type InitializedType = Self;
type UninitializedType = UnIntiTrainRef;
}
impl From<&TrainController<MapStateInitialized>> for IntiTrainRef{
fn from(value: &TrainController<MapStateInitialized>) -> Self {
IntiTrainRef{
train: value
}
}
}