notion_tools/structs/
block.rs

1use crate::structs::common::*;
2use fxhash::FxHashMap;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, Default)]
6pub struct Bookmark {
7    #[serde(default = "Vec::default")]
8    pub caption: Vec<RichText>,
9    #[serde(default = "String::new")]
10    pub url: String,
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize, Default)]
14pub struct BulletedListItem {
15    #[serde(default = "Vec::default")]
16    pub rich_text: Vec<RichText>,
17    #[serde(default = "Color::default")]
18    pub color: Color,
19    #[serde(default = "Vec::default")]
20    pub children: Vec<Block>,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, Default)]
24pub struct Callout {
25    #[serde(default = "Vec::default")]
26    pub rich_text: Vec<RichText>,
27    #[serde(default = "Option::default")]
28    pub icon: Option<Icon>,
29    #[serde(default = "Color::default")]
30    pub color: Color,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, Default)]
34pub struct ChildDatabase {
35    #[serde(default = "String::new")]
36    pub title: String,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, Default)]
40pub struct ChildPage {
41    #[serde(default = "String::new")]
42    pub title: String,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize, Default)]
46pub struct Code {
47    #[serde(default = "Vec::default")]
48    pub caption: Vec<RichText>,
49    #[serde(default = "Vec::default")]
50    pub rich_text: Vec<RichText>,
51    #[serde(default = "String::new")]
52    pub language: String,
53}
54
55#[derive(Debug, Clone, Serialize, Deserialize, Default)]
56pub struct Embed {
57    #[serde(default = "String::new")]
58    pub url: String,
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize, Default)]
62pub struct Equation {
63    #[serde(default = "String::new")]
64    pub expression: String,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, Default)]
68pub struct Heading {
69    #[serde(default = "Vec::default")]
70    pub rich_text: Vec<RichText>,
71    #[serde(default = "Color::default")]
72    pub color: Color,
73    #[serde(default = "bool::default")]
74    pub is_toggleable: bool,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, Default)]
78pub struct Image {
79    #[serde(rename = "type", default = "String::new")]
80    pub type_name: String,
81    #[serde(default = "ExternalUrl::default")]
82    pub external: ExternalUrl,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize, Default)]
86pub struct LinkPreview {
87    #[serde(default = "String::new")]
88    pub url: String,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize, Default)]
92pub struct NumberedListItem {
93    #[serde(default = "Vec::default")]
94    pub rich_text: Vec<RichText>,
95    #[serde(default = "Color::default")]
96    pub color: Color,
97    #[serde(default = "Vec::default")]
98    pub children: Vec<Block>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize, Default)]
102pub struct Pdf {
103    #[serde(rename = "type", default = "String::new")]
104    pub type_name: String,
105    #[serde(default = "ExternalUrl::default")]
106    pub external: ExternalUrl,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize, Default)]
110pub struct Quote {
111    #[serde(default = "Vec::default")]
112    pub rich_text: Vec<RichText>,
113    #[serde(default = "Color::default")]
114    pub color: Color,
115    #[serde(default = "Vec::default")]
116    pub children: Vec<Block>,
117}
118
119#[derive(Debug, Clone, Serialize, Deserialize, Default)]
120pub struct Paragraph {
121    #[serde(default = "Vec::default")]
122    pub rich_text: Vec<RichText>,
123    #[serde(default = "Color::default")]
124    pub color: Color,
125    #[serde(default = "Vec::default")]
126    pub children: Vec<Block>,
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize, Default)]
130pub struct Table {
131    #[serde(default = "u32::default")]
132    pub table_width: u32,
133    #[serde(default = "bool::default")]
134    pub has_column_header: bool,
135    #[serde(default = "bool::default")]
136    pub has_row_header: bool,
137}
138
139#[derive(Debug, Clone, Serialize, Deserialize, Default)]
140pub struct TableRow {
141    #[serde(default = "Vec::default")]
142    pub cells: Vec<RichText>,
143}
144
145#[derive(Debug, Clone, Serialize, Deserialize, Default)]
146pub struct TableOfContents {
147    #[serde(default = "Color::default")]
148    pub color: Color,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize, Default)]
152pub struct ToDo {
153    #[serde(default = "Vec::default")]
154    pub rich_text: Vec<RichText>,
155    #[serde(default = "Color::default")]
156    pub color: Color,
157    #[serde(default = "bool::default")]
158    pub checked: bool,
159    #[serde(default = "Vec::default")]
160    pub children: Vec<Block>,
161}
162
163#[derive(Debug, Clone, Serialize, Deserialize, Default)]
164pub struct ToggleBlock {
165    #[serde(default = "Vec::default")]
166    pub rich_text: Vec<RichText>,
167    #[serde(default = "Color::default")]
168    pub color: Color,
169    #[serde(default = "Vec::default")]
170    pub children: Vec<Block>,
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize, Default)]
174pub struct Video {
175    #[serde(rename = "type", default = "String::new")]
176    pub type_name: String,
177    #[serde(default = "ExternalUrl::default")]
178    pub external: ExternalUrl,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
182pub struct Block {
183    // base properties
184    #[serde(default = "Parent::default", skip_serializing)]
185    pub parent: Parent,
186    #[serde(default = "String::new")]
187    pub object: String,
188    #[serde(default = "String::new", skip_serializing)]
189    pub id: String,
190    #[serde(default = "String::new", skip_serializing)]
191    pub created_time: String,
192    #[serde(default = "String::new", skip_serializing)]
193    pub last_edited_time: String,
194    #[serde(default = "User::default", skip_serializing)]
195    pub created_by: User,
196    #[serde(default = "User::default", skip_serializing)]
197    pub last_edited_by: User,
198    #[serde(default = "bool::default", skip_serializing_if = "std::ops::Not::not")]
199    pub archived: bool,
200    #[serde(default = "bool::default", skip_serializing)]
201    pub in_trash: bool,
202    #[serde(rename = "type", default = "String::new")]
203    pub type_name: String,
204    #[serde(default = "bool::default", skip_serializing)]
205    pub has_children: bool,
206    #[serde(default = "bool::default", skip_serializing)]
207    pub is_togglable: bool,
208
209    // type specific properties
210    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
211    pub bookmark: Option<Bookmark>,
212    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
213    pub breadcrumb: Option<FxHashMap<String, String>>,
214    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
215    pub bulleted_list_item: Option<BulletedListItem>,
216    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
217    pub callout: Option<Callout>,
218    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
219    pub child_database: Option<ChildDatabase>,
220    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
221    pub child_page: Option<ChildPage>,
222    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
223    pub code: Option<Code>,
224    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
225    pub column_list: Option<FxHashMap<String, String>>,
226    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
227    pub column: Option<FxHashMap<String, String>>,
228    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
229    pub divider: Option<FxHashMap<String, String>>,
230    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
231    pub embed: Option<Embed>,
232    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
233    pub equation: Option<Equation>,
234    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
235    pub file: Option<File>,
236    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
237    pub heading_1: Option<Heading>,
238    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
239    pub heading_2: Option<Heading>,
240    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
241    pub heading_3: Option<Heading>,
242    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
243    pub image: Option<Image>,
244    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
245    pub link_preview: Option<LinkPreview>,
246    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
247    pub numbered_list_item: Option<NumberedListItem>,
248    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
249    pub paragraph: Option<Paragraph>,
250    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
251    pub pdf: Option<Pdf>,
252    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
253    pub quote: Option<Quote>,
254    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
255    pub table: Option<Table>,
256    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
257    pub table_row: Option<TableRow>,
258    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
259    pub table_of_contents: Option<TableOfContents>,
260    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
261    pub to_do: Option<ToDo>,
262    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
263    pub toggle: Option<ToggleBlock>,
264    #[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
265    pub video: Option<Video>,
266}
267
268impl Default for Block {
269    fn default() -> Self {
270        let block = Block {
271            parent: Parent {
272                type_name: ParentType::Block,
273                database_id: None,
274                page_id: None,
275                workspace_id: None,
276                block_id: None,
277            },
278            object: "block".to_string(),
279            id: "".to_string(),
280            created_time: "".to_string(),
281            last_edited_time: "".to_string(),
282            created_by: User::default(),
283            last_edited_by: User::default(),
284            archived: false,
285            in_trash: false,
286            type_name: "".to_string(),
287            has_children: false,
288            is_togglable: false,
289            bookmark: None,
290            breadcrumb: None,
291            bulleted_list_item: None,
292            callout: None,
293            child_database: None,
294            child_page: None,
295            code: None,
296            column_list: None,
297            column: None,
298            divider: None,
299            embed: None,
300            equation: None,
301            file: None,
302            heading_1: None,
303            heading_2: None,
304            heading_3: None,
305            image: None,
306            link_preview: None,
307            numbered_list_item: None,
308            paragraph: None,
309            pdf: None,
310            quote: None,
311            table: None,
312            table_row: None,
313            table_of_contents: None,
314            to_do: None,
315            toggle: None,
316            video: None,
317        };
318        return block;
319    }
320}
321
322impl Block {
323    pub fn bookmark(
324        parent_type: ParentType,
325        parent_id: String,
326        caption: String,
327        url: String,
328    ) -> Self {
329        let bookmark = Bookmark {
330            caption: vec![RichText::from_str(caption)],
331            url: url.to_string(),
332        };
333        let block = Block {
334            parent: Parent::from(parent_type, parent_id),
335            type_name: "bookmark".to_string(),
336            bookmark: Some(bookmark),
337            ..Default::default()
338        };
339        return block;
340    }
341
342    pub fn breadcrumb(parent_type: ParentType, parent_id: String) -> Self {
343        let block = Block {
344            parent: Parent::from(parent_type, parent_id),
345            type_name: "breadcrumb".to_string(),
346            breadcrumb: Some(FxHashMap::default()),
347            ..Default::default()
348        };
349        return block;
350    }
351
352    pub fn bulleted_list_item(
353        parent_type: ParentType,
354        parent_id: String,
355        texts: Vec<String>,
356    ) -> Self {
357        let texts = texts
358            .iter()
359            .map(|text| RichText::from_str(text.to_string()))
360            .collect::<Vec<RichText>>();
361        let bulleted_list_item = BulletedListItem {
362            rich_text: texts,
363            ..Default::default()
364        };
365        let block = Block {
366            parent: Parent::from(parent_type, parent_id),
367            type_name: "bulleted_list_item".to_string(),
368            bulleted_list_item: Some(bulleted_list_item),
369            ..Default::default()
370        };
371        return block;
372    }
373
374    pub fn callout(
375        parent_type: ParentType,
376        parent_id: String,
377        text: String,
378        icon: Icon,
379        color: Color,
380    ) -> Self {
381        let rich_text = vec![RichText::from_str(text)];
382        let callout = Callout {
383            rich_text: rich_text,
384            icon: Some(icon),
385            color: color,
386        };
387        let block = Block {
388            parent: Parent::from(parent_type, parent_id),
389            type_name: "callout".to_string(),
390            callout: Some(callout),
391            ..Default::default()
392        };
393        return block;
394    }
395
396    pub fn child_database(parent_type: ParentType, parent_id: String, title: String) -> Self {
397        let child_database = ChildDatabase {
398            title: title.to_string(),
399        };
400        let block = Block {
401            parent: Parent::from(parent_type, parent_id),
402            type_name: "child_database".to_string(),
403            child_database: Some(child_database),
404            ..Default::default()
405        };
406        return block;
407    }
408
409    pub fn child_page(parent_type: ParentType, parent_id: String, title: String) -> Self {
410        let child_page = ChildPage {
411            title: title.to_string(),
412        };
413        let block = Block {
414            type_name: "child_page".to_string(),
415            child_page: Some(child_page),
416            parent: Parent::from(parent_type, parent_id),
417            ..Default::default()
418        };
419        return block;
420    }
421
422    pub fn code(
423        parent_type: ParentType,
424        parent_id: String,
425        caption: String,
426        language: String,
427        texts: Vec<String>,
428    ) -> Self {
429        let caption = vec![RichText::from_str(caption)];
430        let texts = texts
431            .iter()
432            .map(|text| RichText::from_str(text.to_string()))
433            .collect::<Vec<RichText>>();
434        let code = Code {
435            caption: caption,
436            rich_text: texts,
437            language: language.to_string(),
438        };
439        let block = Block {
440            parent: Parent::from(parent_type, parent_id),
441            type_name: "code".to_string(),
442            code: Some(code),
443            ..Default::default()
444        };
445        return block;
446    }
447
448    pub fn column_list(parent_type: ParentType, parent_id: String) -> Self {
449        let block = Block {
450            parent: Parent::from(parent_type, parent_id),
451            type_name: "column_list".to_string(),
452            column_list: Some(FxHashMap::default()),
453            ..Default::default()
454        };
455        return block;
456    }
457
458    pub fn column(parent_type: ParentType, parent_id: String) -> Self {
459        let block = Block {
460            parent: Parent::from(parent_type, parent_id),
461            type_name: "column".to_string(),
462            column: Some(FxHashMap::default()),
463            ..Default::default()
464        };
465        return block;
466    }
467
468    pub fn divider(parent_type: ParentType, parent_id: String) -> Self {
469        let block = Block {
470            parent: Parent::from(parent_type, parent_id),
471            type_name: "divider".to_string(),
472            divider: Some(FxHashMap::default()),
473            ..Default::default()
474        };
475        return block;
476    }
477
478    pub fn embed(parent_type: ParentType, parent_id: String, url: String) -> Self {
479        let embed = Embed {
480            url: url.to_string(),
481        };
482        let block = Block {
483            parent: Parent::from(parent_type, parent_id),
484            type_name: "embed".to_string(),
485            embed: Some(embed),
486            ..Default::default()
487        };
488        return block;
489    }
490
491    pub fn equation(parent_type: ParentType, parent_id: String, expression: String) -> Self {
492        let equation = Equation {
493            expression: expression.to_string(),
494        };
495        let block = Block {
496            parent: Parent::from(parent_type, parent_id),
497            type_name: "equation".to_string(),
498            equation: Some(equation),
499            ..Default::default()
500        };
501        return block;
502    }
503
504    pub fn file(parent_type: ParentType, parent_id: String) -> Self {
505        let block = Block {
506            parent: Parent::from(parent_type, parent_id),
507            type_name: "file".to_string(),
508            file: Some(File::default()),
509            ..Default::default()
510        };
511        return block;
512    }
513
514    pub fn heading_1(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
515        let texts = texts
516            .iter()
517            .map(|text| RichText::from_str(text.to_string()))
518            .collect::<Vec<RichText>>();
519        let heading = Heading {
520            rich_text: texts,
521            ..Default::default()
522        };
523        let block = Block {
524            parent: Parent::from(parent_type, parent_id),
525            type_name: "heading_1".to_string(),
526            heading_1: Some(heading),
527            ..Default::default()
528        };
529        return block;
530    }
531
532    pub fn heading_2(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
533        let texts = texts
534            .iter()
535            .map(|text| RichText::from_str(text.to_string()))
536            .collect::<Vec<RichText>>();
537        let heading = Heading {
538            rich_text: texts,
539            ..Default::default()
540        };
541        let block = Block {
542            parent: Parent::from(parent_type, parent_id),
543            type_name: "heading_2".to_string(),
544            heading_2: Some(heading),
545            ..Default::default()
546        };
547        return block;
548    }
549
550    pub fn heading_3(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
551        let texts = texts
552            .iter()
553            .map(|text| RichText::from_str(text.to_string()))
554            .collect::<Vec<RichText>>();
555        let heading = Heading {
556            rich_text: texts,
557            ..Default::default()
558        };
559        let block = Block {
560            parent: Parent::from(parent_type, parent_id),
561            type_name: "heading_3".to_string(),
562            heading_3: Some(heading),
563            ..Default::default()
564        };
565        return block;
566    }
567
568    pub fn image(parent_type: ParentType, parent_id: String, url: String) -> Self {
569        let external = ExternalUrl {
570            url: url.to_string(),
571        };
572        let image = Image {
573            type_name: "external".to_string(),
574            external: external,
575        };
576        let block = Block {
577            parent: Parent::from(parent_type, parent_id),
578            type_name: "image".to_string(),
579            image: Some(image),
580            ..Default::default()
581        };
582        return block;
583    }
584
585    pub fn link_preview(parent_type: ParentType, parent_id: String, url: String) -> Self {
586        let link_preview = LinkPreview {
587            url: url.to_string(),
588        };
589        let block = Block {
590            parent: Parent::from(parent_type, parent_id),
591            type_name: "link_preview".to_string(),
592            link_preview: Some(link_preview),
593            ..Default::default()
594        };
595        return block;
596    }
597
598    pub fn numbered_list_item(
599        parent_type: ParentType,
600        parent_id: String,
601        texts: Vec<String>,
602    ) -> Self {
603        let texts = texts
604            .iter()
605            .map(|text| RichText::from_str(text.to_string()))
606            .collect::<Vec<RichText>>();
607        let numbered_list_item = NumberedListItem {
608            rich_text: texts,
609            ..Default::default()
610        };
611        let block = Block {
612            parent: Parent::from(parent_type, parent_id),
613            type_name: "numbered_list_item".to_string(),
614            numbered_list_item: Some(numbered_list_item),
615            ..Default::default()
616        };
617        return block;
618    }
619
620    pub fn paragraph(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
621        let texts = texts
622            .iter()
623            .map(|text| RichText::from_str(text.to_string()))
624            .collect::<Vec<RichText>>();
625        let paragraph = Paragraph {
626            rich_text: texts,
627            ..Default::default()
628        };
629        let block = Block {
630            parent: Parent::from(parent_type, parent_id),
631            type_name: "paragraph".to_string(),
632            paragraph: Some(paragraph),
633            ..Default::default()
634        };
635        return block;
636    }
637
638    pub fn pdf(parent_type: ParentType, parent_id: String, url: String) -> Self {
639        let external = ExternalUrl {
640            url: url.to_string(),
641        };
642        let pdf = Pdf {
643            type_name: "external".to_string(),
644            external: external,
645        };
646        let block = Block {
647            parent: Parent::from(parent_type, parent_id),
648            type_name: "pdf".to_string(),
649            pdf: Some(pdf),
650            ..Default::default()
651        };
652        return block;
653    }
654
655    pub fn quote(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
656        let texts = texts
657            .iter()
658            .map(|text| RichText::from_str(text.to_string()))
659            .collect::<Vec<RichText>>();
660        let quote = Quote {
661            rich_text: texts,
662            ..Default::default()
663        };
664        let block = Block {
665            parent: Parent::from(parent_type, parent_id),
666            type_name: "quote".to_string(),
667            quote: Some(quote),
668            ..Default::default()
669        };
670        return block;
671    }
672
673    pub fn table(parent_type: ParentType, parent_id: String) -> Self {
674        let block = Block {
675            parent: Parent::from(parent_type, parent_id),
676            type_name: "table".to_string(),
677            table: Some(Table::default()),
678            ..Default::default()
679        };
680        return block;
681    }
682
683    pub fn table_row(parent_type: ParentType, parent_id: String, cells: Vec<String>) -> Self {
684        let cells = cells
685            .iter()
686            .map(|cell| RichText::from_str(cell.to_string()))
687            .collect::<Vec<RichText>>();
688        let table_row = TableRow { cells: cells };
689        let block = Block {
690            parent: Parent::from(parent_type, parent_id),
691            type_name: "table_row".to_string(),
692            table_row: Some(table_row),
693            ..Default::default()
694        };
695        return block;
696    }
697
698    pub fn table_of_contents(parent_type: ParentType, parent_id: String) -> Self {
699        let block = Block {
700            parent: Parent::from(parent_type, parent_id),
701            type_name: "table_of_contents".to_string(),
702            table_of_contents: Some(TableOfContents::default()),
703            ..Default::default()
704        };
705        return block;
706    }
707
708    pub fn to_do(
709        parent_type: ParentType,
710        parent_id: String,
711        texts: Vec<String>,
712        checked: bool,
713    ) -> Self {
714        let texts = texts
715            .iter()
716            .map(|text| RichText::from_str(text.to_string()))
717            .collect::<Vec<RichText>>();
718        let to_do = ToDo {
719            rich_text: texts,
720            checked: checked,
721            ..Default::default()
722        };
723        let block = Block {
724            parent: Parent::from(parent_type, parent_id),
725            type_name: "to_do".to_string(),
726            to_do: Some(to_do),
727            ..Default::default()
728        };
729        return block;
730    }
731
732    pub fn toggle_blocks(parent_type: ParentType, parent_id: String, texts: Vec<String>) -> Self {
733        let texts = texts
734            .iter()
735            .map(|text| RichText::from_str(text.to_string()))
736            .collect::<Vec<RichText>>();
737        let toggle = ToggleBlock {
738            rich_text: texts,
739            ..Default::default()
740        };
741        let block = Block {
742            parent: Parent::from(parent_type, parent_id),
743            type_name: "toggle".to_string(),
744            toggle: Some(toggle),
745            ..Default::default()
746        };
747        return block;
748    }
749
750    pub fn video(parent_type: ParentType, parent_id: String, url: String) -> Self {
751        let external = ExternalUrl {
752            url: url.to_string(),
753        };
754        let video = Video {
755            type_name: "external".to_string(),
756            external: external,
757        };
758        let block = Block {
759            parent: Parent::from(parent_type, parent_id),
760            type_name: "video".to_string(),
761            video: Some(video),
762            ..Default::default()
763        };
764        return block;
765    }
766}
767
768#[derive(Debug, Clone, Serialize, Deserialize, Default)]
769pub struct BlockResponse {
770    #[serde(default = "String::new")]
771    pub object: String,
772    #[serde(default = "u32::default", skip_serializing)]
773    pub status: u32,
774    #[serde(default = "String::new", skip_serializing)]
775    pub code: String,
776    #[serde(default = "String::new", skip_serializing)]
777    pub message: String,
778    #[serde(default = "Vec::new")]
779    pub results: Vec<Block>,
780}
781
782#[derive(Debug, Clone, Serialize, Deserialize, Default)]
783pub struct BlockBody {
784    #[serde(default = "Vec::default")]
785    pub children: Vec<Block>,
786}