Skip to content

Commit

Permalink
add simple methods for string conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
theaddonn committed Oct 3, 2024
1 parent fd7e777 commit af47b6c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/form/src/forms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ pub enum Form {
Simple(SimpleForm),
}

impl TryFrom<String> for Form {
type Error = serde_json::Error;

fn try_from(value: String) -> Result<Self, Self::Error> {
Self::try_from(value.as_str())
}
}

impl TryFrom<&str> for Form {
type Error = serde_json::Error;

fn try_from(value: &str) -> Result<Self, Self::Error> {
serde_json::from_str(value)
}
}

impl TryFrom<Form> for String {
type Error = serde_json::Error;

fn try_from(value: Form) -> Result<Self, Self::Error> {
serde_json::to_string(&value)
}
}

#[cfg(test)]
mod test {
use crate::elems::button::{Button, ButtonImage};
Expand Down

0 comments on commit af47b6c

Please sign in to comment.