rust_tdlib/types/
get_web_page_preview.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Returns a web page preview by the text of the message. Do not call this function too often. Returns a 404 error if the web page has no preview
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct GetWebPagePreview {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Message text with formatting
14    text: FormattedText,
15
16    #[serde(rename(serialize = "@type"))]
17    td_type: String,
18}
19
20impl RObject for GetWebPagePreview {
21    #[doc(hidden)]
22    fn extra(&self) -> Option<&str> {
23        self.extra.as_deref()
24    }
25    #[doc(hidden)]
26    fn client_id(&self) -> Option<i32> {
27        self.client_id
28    }
29}
30
31impl RFunction for GetWebPagePreview {}
32
33impl GetWebPagePreview {
34    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
35        Ok(serde_json::from_str(json.as_ref())?)
36    }
37    pub fn builder() -> GetWebPagePreviewBuilder {
38        let mut inner = GetWebPagePreview::default();
39        inner.extra = Some(Uuid::new_v4().to_string());
40
41        inner.td_type = "getWebPagePreview".to_string();
42
43        GetWebPagePreviewBuilder { inner }
44    }
45
46    pub fn text(&self) -> &FormattedText {
47        &self.text
48    }
49}
50
51#[doc(hidden)]
52pub struct GetWebPagePreviewBuilder {
53    inner: GetWebPagePreview,
54}
55
56#[deprecated]
57pub type RTDGetWebPagePreviewBuilder = GetWebPagePreviewBuilder;
58
59impl GetWebPagePreviewBuilder {
60    pub fn build(&self) -> GetWebPagePreview {
61        self.inner.clone()
62    }
63
64    pub fn text<T: AsRef<FormattedText>>(&mut self, text: T) -> &mut Self {
65        self.inner.text = text.as_ref().clone();
66        self
67    }
68}
69
70impl AsRef<GetWebPagePreview> for GetWebPagePreview {
71    fn as_ref(&self) -> &GetWebPagePreview {
72        self
73    }
74}
75
76impl AsRef<GetWebPagePreview> for GetWebPagePreviewBuilder {
77    fn as_ref(&self) -> &GetWebPagePreview {
78        &self.inner
79    }
80}