solana: add FromStr for cluster

This commit is contained in:
Ryan Heywood 2024-12-02 03:30:52 -05:00
parent 78e274164a
commit c336079b05
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 13 additions and 0 deletions

View File

@ -62,6 +62,19 @@ pub enum Cluster {
Mainnet,
}
impl std::str::FromStr for Cluster {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"devnet" => Ok(Self::Devnet),
"testnet" => Ok(Self::Testnet),
"mainnet" => Ok(Self::Mainnet),
_ => Err("Invalid value"),
}
}
}
impl std::fmt::Display for Cluster {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {