use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Hash, PartialEq, Serialize)]
pub struct Contents {
pub(super) text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub(super) emoji: Option<bool>,
}
impl Contents {
pub fn from_text(text: impl ToString) -> Self {
Into::<Self>::into(text.to_string())
}
pub fn with_emoji(mut self, emoji: bool) -> Self {
self.emoji = Some(emoji);
self
}
}
impl AsRef<str> for Contents {
fn as_ref(&self) -> &str {
&self.text
}
}
impl From<String> for Contents {
fn from(text: String) -> Self {
Self { text, emoji: None }
}
}
impl From<&String> for Contents {
fn from(text: &String) -> Self {
text.as_str().into()
}
}
impl From<&str> for Contents {
fn from(text: &str) -> Self {
Self::from_text(text)
}
}