acme_sdk/core/
primitives.rs

1/*
2   Appellation: primitives
3   Context:
4   Creator: FL03 <jo3mccain@icloud.com>
5   Description:
6       ... Summary ...
7*/
8pub use common::*;
9pub use utils::*;
10
11mod common {
12    pub use constants::*;
13    pub use controllers::*;
14    pub use types::*;
15
16    mod constants {
17        pub const COINBASE_API_ENDPOINT: &str = "https://coinbase.com/api/v2";
18        pub const COINBASE_PRO_ENDPOINT: &str = "https://pro.coinbase.com/api";
19        pub const STANDARD_OAUTH_TOKEN_PATH: &str = "oauth/token";
20    }
21
22    mod controllers {
23        /// Outlines the required functionality of an Exchangeable item
24        pub trait Exchangeable<Act, Conf, Cont, Data> {
25            fn actor(&self, context: Cont) -> Act
26                where
27                    Self: Sized;
28            fn configure(&self, config: Conf) -> Result<Self, config::ConfigError>
29                where
30                    Self: Sized;
31            fn create(&self, data: Vec<Data>) -> Self
32                where
33                    Self: Sized;
34            fn describe(&self) -> String
35                where
36                    Self: Sized;
37        }
38
39        /// Outlines the required functionality of a malleable item
40        /// def. Malleable is defined as the characteristic of being allowed to make alterations
41        pub trait Malleable<Actor, Conf, Cont, Data> {
42            fn action(&self, actor: Actor) -> Self
43                where
44                    Self: Sized;
45            fn configure(&self) -> Result<Self, config::ConfigError>
46                where
47                    Self: Sized;
48            fn create(&self, actor: Actor, config: Conf) -> Self
49                where
50                    Self: Sized;
51        }
52
53        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
54        pub enum Shapes {
55            Hexagon,
56            Octagon,
57            Pentagon,
58            Square,
59            Triangle,
60        }
61
62        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
63        pub struct Transaction<T = String> {
64            pub id: u64,
65            pub hash: String,
66            pub key: String,
67            pub timestamp: i64,
68            pub data: Vec<T>,
69        }
70
71        impl<T> Transaction<T> {
72            fn create(id: u64, hash: String, key: String, timestamp: i64, data: Vec<T>) -> Self {
73                Self {
74                    id,
75                    hash,
76                    key,
77                    timestamp,
78                    data,
79                }
80            }
81            pub fn new(id: u64, hash: String, key: String, timestamp: i64, data: Vec<T>) -> Self {
82                Self::create(id, hash, key, timestamp, data)
83            }
84        }
85
86        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
87        pub struct Container<T = String> {
88            pub id: u64,
89            pub hash: String,
90            pub key: String,
91            pub nonce: u64,
92            pub secret: String,
93            pub timestamp: i64,
94            pub transactions: Vec<T>,
95        }
96
97        impl<T> Container<T> {
98            fn create(
99                id: u64,
100                hash: String,
101                key: String,
102                nonce: u64,
103                secret: String,
104                timestamp: i64,
105                transactions: Vec<T>,
106            ) -> Self {
107                Self {
108                    id,
109                    hash,
110                    key,
111                    nonce,
112                    secret,
113                    timestamp,
114                    transactions,
115                }
116            }
117            pub fn new(
118                id: u64,
119                hash: String,
120                key: String,
121                nonce: u64,
122                secret: String,
123                timestamp: i64,
124                transactions: Vec<T>,
125            ) -> Self {
126                Self::create(id, hash, key, nonce, secret, timestamp, transactions)
127            }
128        }
129
130        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
131        pub enum Alias {
132            Personal,
133            Social,
134            Work,
135        }
136
137        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
138        pub enum Abbr<T> {
139            Full(T),
140            Short(T),
141        }
142
143        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
144        pub enum Addresses {
145            Street {
146                primary: String,
147                secondary: String,
148                city: String,
149                state: String,
150
151                zip_code: String,
152            },
153        }
154
155        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
156        pub enum Names {
157            FullName {
158                prefix: String,
159                first: String,
160                middle: String,
161                last: String,
162                suffix: String,
163            },
164            NameOnly {
165                first: String,
166                middle: String,
167                last: String,
168            },
169        }
170
171        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
172        pub struct Appellation {
173            pub alias: String,
174            pub name: String,
175        }
176
177        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
178        pub struct Descriptor {
179            pub id: u64,
180            pub hash: String,
181            pub key: String,
182            pub title: String,
183            pub audience: String,
184            pub content: String,
185            pub data: Vec<String>,
186        }
187
188        /// Destined to control the named objects with characteristics found in Descriptor
189        #[derive(Clone, Debug, Hash, PartialEq, serde::Deserialize, serde::Serialize)]
190        pub enum Descriptors {
191            Basic(Descriptor),
192        }
193    }
194
195    mod types {
196        /// Describes a boxed dynamic error with Send, Sync and 'static tags enabled
197        pub type AsyncError = Box<dyn std::error::Error + Send + Sync + 'static>;
198        /// Describes a boxed dynamic error
199        pub type StandardError = Box<dyn std::error::Error>;
200        /// Describes a configuration builder in their default state
201        pub type DefaultConfigBuilder = config::ConfigBuilder<config::builder::DefaultState>;
202        /// Describes the result of a collection of configuration files
203        pub type ConfigFileCollection =
204        Vec<config::File<config::FileSourceFile, config::FileFormat>>;
205    }
206}
207
208mod utils {
209    /// Creates a collection of configuration files found within the working directory and following the provided pattern
210    pub fn collect_config_files(pattern: &str, required: bool) -> crate::ConfigFileCollection {
211        let f = |pat: &str, opt: bool| {
212            glob::glob(pat)
213                .unwrap()
214                .map(|path| config::File::from(path.unwrap()).required(opt))
215                .collect::<Vec<_>>()
216        };
217        f(pattern, required)
218    }
219}
220
221#[cfg(test)]
222mod tests {
223    #[test]
224    fn test() {
225        let f = |x: usize| x.pow(x.try_into().unwrap());
226        assert_eq!(f(2), 4)
227    }
228}