feat: added helper function for turning Formula outputs into String
This commit is contained in:
parent
9e76dbbcad
commit
43a48f6655
1 changed files with 33 additions and 1 deletions
34
src/lib.rs
34
src/lib.rs
|
|
@ -5,8 +5,8 @@ use lazy_static::lazy_static;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::de::Error as SerdeError;
|
use serde::de::Error as SerdeError;
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use serde_json::json;
|
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
use serde_json::json;
|
||||||
use surf::http::StatusCode;
|
use surf::http::StatusCode;
|
||||||
|
|
||||||
use futures_core::future::BoxFuture;
|
use futures_core::future::BoxFuture;
|
||||||
|
|
@ -1213,6 +1213,38 @@ pub enum Formula {
|
||||||
Unsupported,
|
Unsupported,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToString for Formula {
|
||||||
|
fn to_string(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Formula::String {
|
||||||
|
string: Some(string),
|
||||||
|
..
|
||||||
|
} => string.to_owned(),
|
||||||
|
Formula::Number {
|
||||||
|
number: Some(number),
|
||||||
|
..
|
||||||
|
} => format!("{number}"),
|
||||||
|
Formula::Boolean {
|
||||||
|
boolean: Some(boolean),
|
||||||
|
..
|
||||||
|
} => format!("{boolean}"),
|
||||||
|
Formula::Date {
|
||||||
|
date: Some(date), ..
|
||||||
|
} => format!("{date}"),
|
||||||
|
|
||||||
|
Formula::Unsupported => {
|
||||||
|
log::warn!("User tried stringifying unsupported formula");
|
||||||
|
"Formula output unsupported".to_owned()
|
||||||
|
}
|
||||||
|
|
||||||
|
Formula::Number { number: None, .. }
|
||||||
|
| Formula::Date { date: None, .. }
|
||||||
|
| Formula::Boolean { boolean: None, .. }
|
||||||
|
| Formula::String { string: None, .. } => "".to_owned(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
pub struct PartialUser {
|
pub struct PartialUser {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue