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
use core::fmt::Display;
use core::str::FromStr;

use serde::Serialize;
use thiserror::Error;

/// An identifier for a cardano network
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub enum NetworkId {
    Mainnet,
    Testnet,
}

impl Display for NetworkId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            Self::Mainnet => "mainnet",
            Self::Testnet => "testnet",
        })
    }
}

impl FromStr for NetworkId {
    type Err = NetworkInfoFromStrError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "mainnet" => Ok(Self::Mainnet),
            "testnet" => Ok(Self::Testnet),
            s => Err(NetworkInfoFromStrError(s.to_string())),
        }
    }
}
#[derive(Debug, Error)]
#[error("unknown variant: {0}")]
pub struct NetworkInfoFromStrError(String);