jacquard_api/blog_pckt/block/
code_block.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10use jacquard_common::{CowStr, BosStr, 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::{Serialize, Deserialize};
23
24#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
25#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
26pub struct CodeBlock<S: BosStr = DefaultStr> {
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub language: Option<S>,
30 pub plaintext: S,
32 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
33 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
34}
35
36impl<S: BosStr> LexiconSchema for CodeBlock<S> {
37 fn nsid() -> &'static str {
38 "blog.pckt.block.codeBlock"
39 }
40 fn def_name() -> &'static str {
41 "main"
42 }
43 fn lexicon_doc() -> LexiconDoc<'static> {
44 lexicon_doc_blog_pckt_block_codeBlock()
45 }
46 fn validate(&self) -> Result<(), ConstraintError> {
47 if let Some(ref value) = self.language {
48 #[allow(unused_comparisons)]
49 if <str>::len(value.as_ref()) > 50usize {
50 return Err(ConstraintError::MaxLength {
51 path: ValidationPath::from_field("language"),
52 max: 50usize,
53 actual: <str>::len(value.as_ref()),
54 });
55 }
56 }
57 Ok(())
58 }
59}
60
61fn lexicon_doc_blog_pckt_block_codeBlock() -> LexiconDoc<'static> {
62 #[allow(unused_imports)]
63 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
64 use jacquard_lexicon::lexicon::*;
65 use alloc::collections::BTreeMap;
66 LexiconDoc {
67 lexicon: Lexicon::Lexicon1,
68 id: CowStr::new_static("blog.pckt.block.codeBlock"),
69 defs: {
70 let mut map = BTreeMap::new();
71 map.insert(
72 SmolStr::new_static("main"),
73 LexUserType::Object(LexObject {
74 required: Some(vec![SmolStr::new_static("plaintext")]),
75 properties: {
76 #[allow(unused_mut)]
77 let mut map = BTreeMap::new();
78 map.insert(
79 SmolStr::new_static("language"),
80 LexObjectProperty::String(LexString {
81 description: Some(
82 CowStr::new_static(
83 "Programming language for syntax highlighting",
84 ),
85 ),
86 max_length: Some(50usize),
87 ..Default::default()
88 }),
89 );
90 map.insert(
91 SmolStr::new_static("plaintext"),
92 LexObjectProperty::String(LexString {
93 description: Some(CowStr::new_static("The code content")),
94 ..Default::default()
95 }),
96 );
97 map
98 },
99 ..Default::default()
100 }),
101 );
102 map
103 },
104 ..Default::default()
105 }
106}