use crate::errors::*;
use crate::types::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TextQuote {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
text: FormattedText,
rich_texts: Vec<RichText>,
position: i64,
is_manual: bool,
}
impl RObject for TextQuote {
#[doc(hidden)]
fn td_name(&self) -> &'static str {
"textQuote"
}
#[doc(hidden)]
fn extra(&self) -> Option<String> {
self.extra.clone()
}
fn to_json(&self) -> RTDResult<String> {
Ok(serde_json::to_string(self)?)
}
}
impl TextQuote {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
Ok(serde_json::from_str(json.as_ref())?)
}
pub fn builder() -> RTDTextQuoteBuilder {
let inner = TextQuote {
td_name: "textQuote".to_string(),
extra: Some(Uuid::new_v4().to_string()),
..Default::default()
};
RTDTextQuoteBuilder { inner }
}
pub fn text(&self) -> &FormattedText {
&self.text
}
pub fn rich_texts(&self) -> &Vec<RichText> {
&self.rich_texts
}
pub fn position(&self) -> i64 {
self.position
}
pub fn is_manual(&self) -> bool {
self.is_manual
}
}
#[doc(hidden)]
pub struct RTDTextQuoteBuilder {
inner: TextQuote,
}
impl RTDTextQuoteBuilder {
pub fn build(&self) -> TextQuote {
self.inner.clone()
}
pub fn text<T: AsRef<FormattedText>>(&mut self, text: T) -> &mut Self {
self.inner.text = text.as_ref().clone();
self
}
pub fn rich_texts(&mut self, rich_texts: Vec<RichText>) -> &mut Self {
self.inner.rich_texts = rich_texts;
self
}
pub fn position(&mut self, position: i64) -> &mut Self {
self.inner.position = position;
self
}
pub fn is_manual(&mut self, is_manual: bool) -> &mut Self {
self.inner.is_manual = is_manual;
self
}
}
impl AsRef<TextQuote> for TextQuote {
fn as_ref(&self) -> &TextQuote {
self
}
}
impl AsRef<TextQuote> for RTDTextQuoteBuilder {
fn as_ref(&self) -> &TextQuote {
&self.inner
}
}