Skip to main content

jacquard_api/blog_pckt/block/
code_block.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: blog.pckt.block.codeBlock
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
11
12#[allow(unused_imports)]
13use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
14use jacquard_common::deps::smol_str::SmolStr;
15use jacquard_common::types::value::Data;
16use jacquard_derive::IntoStatic;
17use jacquard_lexicon::lexicon::LexiconDoc;
18use jacquard_lexicon::schema::LexiconSchema;
19
20#[allow(unused_imports)]
21use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
22use serde::{Deserialize, Serialize};
23
24#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
25#[serde(
26    rename_all = "camelCase",
27    bound(deserialize = "S: Deserialize<'de> + BosStr")
28)]
29pub struct CodeBlock<S: BosStr = DefaultStr> {
30    ///Programming language for syntax highlighting
31    #[serde(skip_serializing_if = "Option::is_none")]
32    pub language: Option<S>,
33    ///The code content
34    pub plaintext: S,
35    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
36    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
37}
38
39impl<S: BosStr> LexiconSchema for CodeBlock<S> {
40    fn nsid() -> &'static str {
41        "blog.pckt.block.codeBlock"
42    }
43    fn def_name() -> &'static str {
44        "main"
45    }
46    fn lexicon_doc() -> LexiconDoc<'static> {
47        lexicon_doc_blog_pckt_block_codeBlock()
48    }
49    fn validate(&self) -> Result<(), ConstraintError> {
50        if let Some(ref value) = self.language {
51            #[allow(unused_comparisons)]
52            if <str>::len(value.as_ref()) > 50usize {
53                return Err(ConstraintError::MaxLength {
54                    path: ValidationPath::from_field("language"),
55                    max: 50usize,
56                    actual: <str>::len(value.as_ref()),
57                });
58            }
59        }
60        Ok(())
61    }
62}
63
64fn lexicon_doc_blog_pckt_block_codeBlock() -> LexiconDoc<'static> {
65    use alloc::collections::BTreeMap;
66    #[allow(unused_imports)]
67    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
68    use jacquard_lexicon::lexicon::*;
69    LexiconDoc {
70        lexicon: Lexicon::Lexicon1,
71        id: CowStr::new_static("blog.pckt.block.codeBlock"),
72        defs: {
73            let mut map = BTreeMap::new();
74            map.insert(
75                SmolStr::new_static("main"),
76                LexUserType::Object(LexObject {
77                    required: Some(vec![SmolStr::new_static("plaintext")]),
78                    properties: {
79                        #[allow(unused_mut)]
80                        let mut map = BTreeMap::new();
81                        map.insert(
82                            SmolStr::new_static("language"),
83                            LexObjectProperty::String(LexString {
84                                description: Some(CowStr::new_static(
85                                    "Programming language for syntax highlighting",
86                                )),
87                                max_length: Some(50usize),
88                                ..Default::default()
89                            }),
90                        );
91                        map.insert(
92                            SmolStr::new_static("plaintext"),
93                            LexObjectProperty::String(LexString {
94                                description: Some(CowStr::new_static("The code content")),
95                                ..Default::default()
96                            }),
97                        );
98                        map
99                    },
100                    ..Default::default()
101                }),
102            );
103            map
104        },
105        ..Default::default()
106    }
107}