mithril_common/entities/
mithril_network.rs

1use std::str::FromStr;
2
3use crate::StdError;
4
5/// Representation of a Mithril network
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct MithrilNetwork(String);
8
9impl MithrilNetwork {
10    /// Create a new MithrilNetwork instance
11    pub fn new(name: String) -> Self {
12        Self(name)
13    }
14
15    /// Create a dummy MithrilNetwork instance for testing purposes
16    pub fn dummy() -> Self {
17        Self("dummy".to_string())
18    }
19
20    /// Retrieve the name of the Mithril network
21    pub fn name(&self) -> &str {
22        &self.0
23    }
24}
25
26impl From<String> for MithrilNetwork {
27    fn from(name: String) -> Self {
28        MithrilNetwork::new(name)
29    }
30}
31
32impl From<&str> for MithrilNetwork {
33    fn from(name: &str) -> Self {
34        MithrilNetwork::new(name.to_string())
35    }
36}
37
38impl FromStr for MithrilNetwork {
39    type Err = StdError;
40
41    fn from_str(s: &str) -> Result<Self, Self::Err> {
42        Ok(MithrilNetwork::new(s.to_string()))
43    }
44}