Skip to content

Commit

Permalink
chore: FromStr impl to convert str to StorageClass enum (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets authored Sep 19, 2024
1 parent 3864e35 commit 5cb812a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Duration;
use std::{str::FromStr, time::Duration};

use typed_builder::TypedBuilder;

Expand Down Expand Up @@ -128,6 +128,18 @@ impl From<api::StorageClass> for StorageClass {
}
}

impl FromStr for StorageClass {
type Err = ConvertError;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"unspecified" => Ok(Self::Unspecified),
"standard" => Ok(Self::Standard),
"express" => Ok(Self::Express),
_ => Err("invalid storage class value".into()),
}
}
}

impl From<StorageClass> for i32 {
fn from(value: StorageClass) -> Self {
api::StorageClass::from(value).into()
Expand Down

0 comments on commit 5cb812a

Please sign in to comment.