Skip to content

Commit

Permalink
Additional JSON value type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
zargony committed Oct 4, 2024
1 parent 8798fad commit 4be9cf2
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions firmware/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,48 @@ pub enum Value {
Object(Vec<(String, Value)>),
}

impl From<()> for Value {
fn from(_value: ()) -> Self {
Self::Null
}
}

impl From<bool> for Value {
fn from(value: bool) -> Self {
Self::Boolean(value)
}
}

impl From<f64> for Value {
fn from(value: f64) -> Self {
Self::Number(value)
}
}

impl From<&str> for Value {
fn from(value: &str) -> Self {
Self::String(value.to_string())
}
}

impl From<String> for Value {
fn from(value: String) -> Self {
Self::String(value)
}
}

impl From<Vec<Value>> for Value {
fn from(value: Vec<Value>) -> Self {
Self::Array(value)
}
}

impl From<Vec<(String, Value)>> for Value {
fn from(value: Vec<(String, Value)>) -> Self {
Self::Object(value)
}
}

impl TryFrom<Value> for bool {
type Error = Error<()>;

Expand Down

0 comments on commit 4be9cf2

Please sign in to comment.