From 43a48f6655df54af919696454954a2f24737758e Mon Sep 17 00:00:00 2001 From: Bram Dingelstad Date: Fri, 7 Mar 2025 16:17:41 +0100 Subject: [PATCH] feat: added helper function for turning Formula outputs into String --- src/lib.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 87a178c..bb0dc6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ use lazy_static::lazy_static; use regex::Regex; use serde::de::Error as SerdeError; use serde::{Deserialize, Deserializer, Serialize}; -use serde_json::json; use serde_json::Value; +use serde_json::json; use surf::http::StatusCode; use futures_core::future::BoxFuture; @@ -1213,6 +1213,38 @@ pub enum Formula { 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)] pub struct PartialUser { pub id: String,