use serde::{Deserialize, Serialize}; use super::contextualize::Contextualize; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] #[serde(tag = "kind", content = "data", rename_all = "snake_case")] pub enum Inline { Text(String), Link { label: String, url: String }, } #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] #[serde(transparent)] pub struct RichText(pub Vec); impl From<&str> for RichText { fn from(value: &str) -> Self { Self(vec![Inline::Text(value.into())]) } } impl Contextualize for RichText { fn render_context(&self) -> String { let mut text = String::new(); for item in &self.0 { match item { Inline::Text(value) => text.push_str(value), Inline::Link { label, url } => { text.push_str(label); text.push_str(" ("); text.push_str(url); text.push(')'); } } } text } }