Skip to content

Commit

Permalink
feat: Added Json type (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
FroVolod authored May 26, 2023
1 parent 48cb8fc commit 13320e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/types/json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use serde_json::Value;

#[derive(Debug, Clone)]
pub struct Json(pub Value);

impl From<Json> for Value {
fn from(item: Json) -> Self {
item.0
}
}

impl std::fmt::Display for Json {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
self.0.fmt(f)
}
}

impl std::str::FromStr for Json {
type Err = color_eyre::eyre::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let json: Value = serde_json::from_str(s).map_err(color_eyre::eyre::Report::msg)?;
Ok(Self(json))
}
}

impl interactive_clap::ToCli for Json {
type CliVariant = Json;
}
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod account_id;
pub mod api_key;
pub mod crypto_hash;
pub mod json;
pub mod path_buf;
pub mod public_key;
pub mod secret_key;
Expand Down

0 comments on commit 13320e5

Please sign in to comment.