starlane_space/space/
config.rs

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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use core::str::FromStr;
use std::ops::Deref;

use crate::space::config::mechtron::MechtronConfig;
use crate::space::particle::{Details, Stub};
use crate::space::point::Point;
use crate::BindConfig;
use serde::{Deserialize, Serialize};
use starlane_primitive_macros::Autobox;

pub mod bind;
pub mod mechtron;

use crate::space::err::ParseErrs;
use crate::space::parse::doc;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PortalKind {
    Mechtron,
    Portal,
}

impl ToString for PortalKind {
    fn to_string(&self) -> String {
        match self {
            PortalKind::Mechtron => "Mechtron".to_string(),
            PortalKind::Portal => "Portal".to_string(),
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Info {
    pub stub: Stub,
    pub kind: PortalKind,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PortalConfig {
    pub max_payload_size: u32,
    pub init_timeout: u64,
    pub frame_timeout: u64,
    pub response_timeout: u64,
}

impl Default for PortalConfig {
    fn default() -> Self {
        Self {
            max_payload_size: 128 * 1024,
            init_timeout: 30,
            frame_timeout: 5,
            response_timeout: 15,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct PointConfig<Body> {
    pub point: Point,
    pub body: Body,
}

impl<Body> Deref for PointConfig<Body> {
    type Target = Body;

    fn deref(&self) -> &Self::Target {
        &self.body
    }
}

#[derive(Autobox)]
pub enum Document {
    BindConfig(BindConfig),
    MechtronConfig(MechtronConfig),
}

impl Document {
   pub fn kind(&self) -> DocKind {
       match self {
           Document::BindConfig(_) => DocKind::BindConfig,
           Document::MechtronConfig(_) => DocKind::MechtronConfig,
       }
   }
}



impl FromStr for Document {
    type Err = ParseErrs;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        doc(s)
    }
}

#[derive(Clone,Hash,Eq,PartialEq,strum_macros::Display,strum_macros::EnumString)]
pub enum DocKind {
    BindConfig,
    MechtronConfig
}

impl AsRef<str> for DocKind {
    fn as_ref(&self) -> &str {
        self.as_ref()
    }
}



#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct ParticleConfigBody {
    pub details: Details,
}