1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_derive::{IntoStatic, lexicon, open_union};
18use jacquard_lexicon::lexicon::LexiconDoc;
19use jacquard_lexicon::schema::LexiconSchema;
20
21#[allow(unused_imports)]
22use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
23use serde::{Serialize, Deserialize};
24use crate::pub_leaflet::blocks::blockquote::Blockquote;
25use crate::pub_leaflet::blocks::bsky_post::BskyPost;
26use crate::pub_leaflet::blocks::button::Button;
27use crate::pub_leaflet::blocks::code::Code;
28use crate::pub_leaflet::blocks::header::Header;
29use crate::pub_leaflet::blocks::horizontal_rule::HorizontalRule;
30use crate::pub_leaflet::blocks::iframe::Iframe;
31use crate::pub_leaflet::blocks::image::Image;
32use crate::pub_leaflet::blocks::math::Math;
33use crate::pub_leaflet::blocks::ordered_list::OrderedList;
34use crate::pub_leaflet::blocks::page::Page;
35use crate::pub_leaflet::blocks::poll::Poll;
36use crate::pub_leaflet::blocks::text::Text;
37use crate::pub_leaflet::blocks::unordered_list::UnorderedList;
38use crate::pub_leaflet::blocks::website::Website;
39use crate::pub_leaflet::pages::canvas;
40
41#[lexicon]
42#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
43#[serde(rename_all = "camelCase")]
44pub struct Block<'a> {
45 #[serde(borrow)]
46 pub block: BlockBlock<'a>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub height: Option<i64>,
49 #[serde(skip_serializing_if = "Option::is_none")]
51 pub rotation: Option<i64>,
52 pub width: i64,
53 pub x: i64,
54 pub y: i64,
55}
56
57
58#[open_union]
59#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
60#[serde(tag = "$type", bound(deserialize = "'de: 'a"))]
61pub enum BlockBlock<'a> {
62 #[serde(rename = "pub.leaflet.blocks.iframe")]
63 Iframe(Box<Iframe<'a>>),
64 #[serde(rename = "pub.leaflet.blocks.text")]
65 Text(Box<Text<'a>>),
66 #[serde(rename = "pub.leaflet.blocks.blockquote")]
67 Blockquote(Box<Blockquote<'a>>),
68 #[serde(rename = "pub.leaflet.blocks.header")]
69 Header(Box<Header<'a>>),
70 #[serde(rename = "pub.leaflet.blocks.image")]
71 Image(Box<Image<'a>>),
72 #[serde(rename = "pub.leaflet.blocks.unorderedList")]
73 UnorderedList(Box<UnorderedList<'a>>),
74 #[serde(rename = "pub.leaflet.blocks.orderedList")]
75 OrderedList(Box<OrderedList<'a>>),
76 #[serde(rename = "pub.leaflet.blocks.website")]
77 Website(Box<Website<'a>>),
78 #[serde(rename = "pub.leaflet.blocks.math")]
79 Math(Box<Math<'a>>),
80 #[serde(rename = "pub.leaflet.blocks.code")]
81 Code(Box<Code<'a>>),
82 #[serde(rename = "pub.leaflet.blocks.horizontalRule")]
83 HorizontalRule(Box<HorizontalRule<'a>>),
84 #[serde(rename = "pub.leaflet.blocks.bskyPost")]
85 BskyPost(Box<BskyPost<'a>>),
86 #[serde(rename = "pub.leaflet.blocks.page")]
87 Page(Box<Page<'a>>),
88 #[serde(rename = "pub.leaflet.blocks.poll")]
89 Poll(Box<Poll<'a>>),
90 #[serde(rename = "pub.leaflet.blocks.button")]
91 Button(Box<Button<'a>>),
92}
93
94
95#[lexicon]
96#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
97#[serde(rename_all = "camelCase")]
98pub struct Canvas<'a> {
99 #[serde(borrow)]
100 pub blocks: Vec<canvas::Block<'a>>,
101 #[serde(skip_serializing_if = "Option::is_none")]
102 #[serde(borrow)]
103 pub id: Option<CowStr<'a>>,
104}
105
106
107#[lexicon]
108#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
109#[serde(rename_all = "camelCase")]
110pub struct Position<'a> {
111 pub block: Vec<i64>,
112 pub offset: i64,
113}
114
115
116#[lexicon]
117#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
118#[serde(rename_all = "camelCase")]
119pub struct Quote<'a> {
120 #[serde(borrow)]
121 pub end: canvas::Position<'a>,
122 #[serde(borrow)]
123 pub start: canvas::Position<'a>,
124}
125
126
127#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
128pub struct TextAlignCenter;
129impl core::fmt::Display for TextAlignCenter {
130 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
131 write!(f, "textAlignCenter")
132 }
133}
134
135
136#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
137pub struct TextAlignLeft;
138impl core::fmt::Display for TextAlignLeft {
139 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
140 write!(f, "textAlignLeft")
141 }
142}
143
144
145#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
146pub struct TextAlignRight;
147impl core::fmt::Display for TextAlignRight {
148 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
149 write!(f, "textAlignRight")
150 }
151}
152
153impl<'a> LexiconSchema for Block<'a> {
154 fn nsid() -> &'static str {
155 "pub.leaflet.pages.canvas"
156 }
157 fn def_name() -> &'static str {
158 "block"
159 }
160 fn lexicon_doc() -> LexiconDoc<'static> {
161 lexicon_doc_pub_leaflet_pages_canvas()
162 }
163 fn validate(&self) -> Result<(), ConstraintError> {
164 Ok(())
165 }
166}
167
168impl<'a> LexiconSchema for Canvas<'a> {
169 fn nsid() -> &'static str {
170 "pub.leaflet.pages.canvas"
171 }
172 fn def_name() -> &'static str {
173 "main"
174 }
175 fn lexicon_doc() -> LexiconDoc<'static> {
176 lexicon_doc_pub_leaflet_pages_canvas()
177 }
178 fn validate(&self) -> Result<(), ConstraintError> {
179 Ok(())
180 }
181}
182
183impl<'a> LexiconSchema for Position<'a> {
184 fn nsid() -> &'static str {
185 "pub.leaflet.pages.canvas"
186 }
187 fn def_name() -> &'static str {
188 "position"
189 }
190 fn lexicon_doc() -> LexiconDoc<'static> {
191 lexicon_doc_pub_leaflet_pages_canvas()
192 }
193 fn validate(&self) -> Result<(), ConstraintError> {
194 Ok(())
195 }
196}
197
198impl<'a> LexiconSchema for Quote<'a> {
199 fn nsid() -> &'static str {
200 "pub.leaflet.pages.canvas"
201 }
202 fn def_name() -> &'static str {
203 "quote"
204 }
205 fn lexicon_doc() -> LexiconDoc<'static> {
206 lexicon_doc_pub_leaflet_pages_canvas()
207 }
208 fn validate(&self) -> Result<(), ConstraintError> {
209 Ok(())
210 }
211}
212
213pub mod block_state {
214
215 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
216 #[allow(unused)]
217 use ::core::marker::PhantomData;
218 mod sealed {
219 pub trait Sealed {}
220 }
221 pub trait State: sealed::Sealed {
223 type Y;
224 type Width;
225 type Block;
226 type X;
227 }
228 pub struct Empty(());
230 impl sealed::Sealed for Empty {}
231 impl State for Empty {
232 type Y = Unset;
233 type Width = Unset;
234 type Block = Unset;
235 type X = Unset;
236 }
237 pub struct SetY<S: State = Empty>(PhantomData<fn() -> S>);
239 impl<S: State> sealed::Sealed for SetY<S> {}
240 impl<S: State> State for SetY<S> {
241 type Y = Set<members::y>;
242 type Width = S::Width;
243 type Block = S::Block;
244 type X = S::X;
245 }
246 pub struct SetWidth<S: State = Empty>(PhantomData<fn() -> S>);
248 impl<S: State> sealed::Sealed for SetWidth<S> {}
249 impl<S: State> State for SetWidth<S> {
250 type Y = S::Y;
251 type Width = Set<members::width>;
252 type Block = S::Block;
253 type X = S::X;
254 }
255 pub struct SetBlock<S: State = Empty>(PhantomData<fn() -> S>);
257 impl<S: State> sealed::Sealed for SetBlock<S> {}
258 impl<S: State> State for SetBlock<S> {
259 type Y = S::Y;
260 type Width = S::Width;
261 type Block = Set<members::block>;
262 type X = S::X;
263 }
264 pub struct SetX<S: State = Empty>(PhantomData<fn() -> S>);
266 impl<S: State> sealed::Sealed for SetX<S> {}
267 impl<S: State> State for SetX<S> {
268 type Y = S::Y;
269 type Width = S::Width;
270 type Block = S::Block;
271 type X = Set<members::x>;
272 }
273 #[allow(non_camel_case_types)]
275 pub mod members {
276 pub struct y(());
278 pub struct width(());
280 pub struct block(());
282 pub struct x(());
284 }
285}
286
287pub struct BlockBuilder<'a, S: block_state::State> {
289 _state: PhantomData<fn() -> S>,
290 _fields: (
291 Option<BlockBlock<'a>>,
292 Option<i64>,
293 Option<i64>,
294 Option<i64>,
295 Option<i64>,
296 Option<i64>,
297 ),
298 _lifetime: PhantomData<&'a ()>,
299}
300
301impl<'a> Block<'a> {
302 pub fn new() -> BlockBuilder<'a, block_state::Empty> {
304 BlockBuilder::new()
305 }
306}
307
308impl<'a> BlockBuilder<'a, block_state::Empty> {
309 pub fn new() -> Self {
311 BlockBuilder {
312 _state: PhantomData,
313 _fields: (None, None, None, None, None, None),
314 _lifetime: PhantomData,
315 }
316 }
317}
318
319impl<'a, S> BlockBuilder<'a, S>
320where
321 S: block_state::State,
322 S::Block: block_state::IsUnset,
323{
324 pub fn block(
326 mut self,
327 value: impl Into<BlockBlock<'a>>,
328 ) -> BlockBuilder<'a, block_state::SetBlock<S>> {
329 self._fields.0 = Option::Some(value.into());
330 BlockBuilder {
331 _state: PhantomData,
332 _fields: self._fields,
333 _lifetime: PhantomData,
334 }
335 }
336}
337
338impl<'a, S: block_state::State> BlockBuilder<'a, S> {
339 pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
341 self._fields.1 = value.into();
342 self
343 }
344 pub fn maybe_height(mut self, value: Option<i64>) -> Self {
346 self._fields.1 = value;
347 self
348 }
349}
350
351impl<'a, S: block_state::State> BlockBuilder<'a, S> {
352 pub fn rotation(mut self, value: impl Into<Option<i64>>) -> Self {
354 self._fields.2 = value.into();
355 self
356 }
357 pub fn maybe_rotation(mut self, value: Option<i64>) -> Self {
359 self._fields.2 = value;
360 self
361 }
362}
363
364impl<'a, S> BlockBuilder<'a, S>
365where
366 S: block_state::State,
367 S::Width: block_state::IsUnset,
368{
369 pub fn width(
371 mut self,
372 value: impl Into<i64>,
373 ) -> BlockBuilder<'a, block_state::SetWidth<S>> {
374 self._fields.3 = Option::Some(value.into());
375 BlockBuilder {
376 _state: PhantomData,
377 _fields: self._fields,
378 _lifetime: PhantomData,
379 }
380 }
381}
382
383impl<'a, S> BlockBuilder<'a, S>
384where
385 S: block_state::State,
386 S::X: block_state::IsUnset,
387{
388 pub fn x(mut self, value: impl Into<i64>) -> BlockBuilder<'a, block_state::SetX<S>> {
390 self._fields.4 = Option::Some(value.into());
391 BlockBuilder {
392 _state: PhantomData,
393 _fields: self._fields,
394 _lifetime: PhantomData,
395 }
396 }
397}
398
399impl<'a, S> BlockBuilder<'a, S>
400where
401 S: block_state::State,
402 S::Y: block_state::IsUnset,
403{
404 pub fn y(mut self, value: impl Into<i64>) -> BlockBuilder<'a, block_state::SetY<S>> {
406 self._fields.5 = Option::Some(value.into());
407 BlockBuilder {
408 _state: PhantomData,
409 _fields: self._fields,
410 _lifetime: PhantomData,
411 }
412 }
413}
414
415impl<'a, S> BlockBuilder<'a, S>
416where
417 S: block_state::State,
418 S::Y: block_state::IsSet,
419 S::Width: block_state::IsSet,
420 S::Block: block_state::IsSet,
421 S::X: block_state::IsSet,
422{
423 pub fn build(self) -> Block<'a> {
425 Block {
426 block: self._fields.0.unwrap(),
427 height: self._fields.1,
428 rotation: self._fields.2,
429 width: self._fields.3.unwrap(),
430 x: self._fields.4.unwrap(),
431 y: self._fields.5.unwrap(),
432 extra_data: Default::default(),
433 }
434 }
435 pub fn build_with_data(
437 self,
438 extra_data: BTreeMap<
439 jacquard_common::deps::smol_str::SmolStr,
440 jacquard_common::types::value::Data<'a>,
441 >,
442 ) -> Block<'a> {
443 Block {
444 block: self._fields.0.unwrap(),
445 height: self._fields.1,
446 rotation: self._fields.2,
447 width: self._fields.3.unwrap(),
448 x: self._fields.4.unwrap(),
449 y: self._fields.5.unwrap(),
450 extra_data: Some(extra_data),
451 }
452 }
453}
454
455fn lexicon_doc_pub_leaflet_pages_canvas() -> LexiconDoc<'static> {
456 #[allow(unused_imports)]
457 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
458 use jacquard_lexicon::lexicon::*;
459 use alloc::collections::BTreeMap;
460 LexiconDoc {
461 lexicon: Lexicon::Lexicon1,
462 id: CowStr::new_static("pub.leaflet.pages.canvas"),
463 defs: {
464 let mut map = BTreeMap::new();
465 map.insert(
466 SmolStr::new_static("block"),
467 LexUserType::Object(LexObject {
468 required: Some(
469 vec![
470 SmolStr::new_static("block"), SmolStr::new_static("x"),
471 SmolStr::new_static("y"), SmolStr::new_static("width")
472 ],
473 ),
474 properties: {
475 #[allow(unused_mut)]
476 let mut map = BTreeMap::new();
477 map.insert(
478 SmolStr::new_static("block"),
479 LexObjectProperty::Union(LexRefUnion {
480 refs: vec![
481 CowStr::new_static("pub.leaflet.blocks.iframe"),
482 CowStr::new_static("pub.leaflet.blocks.text"),
483 CowStr::new_static("pub.leaflet.blocks.blockquote"),
484 CowStr::new_static("pub.leaflet.blocks.header"),
485 CowStr::new_static("pub.leaflet.blocks.image"),
486 CowStr::new_static("pub.leaflet.blocks.unorderedList"),
487 CowStr::new_static("pub.leaflet.blocks.orderedList"),
488 CowStr::new_static("pub.leaflet.blocks.website"),
489 CowStr::new_static("pub.leaflet.blocks.math"),
490 CowStr::new_static("pub.leaflet.blocks.code"),
491 CowStr::new_static("pub.leaflet.blocks.horizontalRule"),
492 CowStr::new_static("pub.leaflet.blocks.bskyPost"),
493 CowStr::new_static("pub.leaflet.blocks.page"),
494 CowStr::new_static("pub.leaflet.blocks.poll"),
495 CowStr::new_static("pub.leaflet.blocks.button")
496 ],
497 ..Default::default()
498 }),
499 );
500 map.insert(
501 SmolStr::new_static("height"),
502 LexObjectProperty::Integer(LexInteger {
503 ..Default::default()
504 }),
505 );
506 map.insert(
507 SmolStr::new_static("rotation"),
508 LexObjectProperty::Integer(LexInteger {
509 ..Default::default()
510 }),
511 );
512 map.insert(
513 SmolStr::new_static("width"),
514 LexObjectProperty::Integer(LexInteger {
515 ..Default::default()
516 }),
517 );
518 map.insert(
519 SmolStr::new_static("x"),
520 LexObjectProperty::Integer(LexInteger {
521 ..Default::default()
522 }),
523 );
524 map.insert(
525 SmolStr::new_static("y"),
526 LexObjectProperty::Integer(LexInteger {
527 ..Default::default()
528 }),
529 );
530 map
531 },
532 ..Default::default()
533 }),
534 );
535 map.insert(
536 SmolStr::new_static("main"),
537 LexUserType::Object(LexObject {
538 required: Some(vec![SmolStr::new_static("blocks")]),
539 properties: {
540 #[allow(unused_mut)]
541 let mut map = BTreeMap::new();
542 map.insert(
543 SmolStr::new_static("blocks"),
544 LexObjectProperty::Array(LexArray {
545 items: LexArrayItem::Ref(LexRef {
546 r#ref: CowStr::new_static("#block"),
547 ..Default::default()
548 }),
549 ..Default::default()
550 }),
551 );
552 map.insert(
553 SmolStr::new_static("id"),
554 LexObjectProperty::String(LexString { ..Default::default() }),
555 );
556 map
557 },
558 ..Default::default()
559 }),
560 );
561 map.insert(
562 SmolStr::new_static("position"),
563 LexUserType::Object(LexObject {
564 required: Some(
565 vec![SmolStr::new_static("block"), SmolStr::new_static("offset")],
566 ),
567 properties: {
568 #[allow(unused_mut)]
569 let mut map = BTreeMap::new();
570 map.insert(
571 SmolStr::new_static("block"),
572 LexObjectProperty::Array(LexArray {
573 items: LexArrayItem::Integer(LexInteger {
574 ..Default::default()
575 }),
576 ..Default::default()
577 }),
578 );
579 map.insert(
580 SmolStr::new_static("offset"),
581 LexObjectProperty::Integer(LexInteger {
582 ..Default::default()
583 }),
584 );
585 map
586 },
587 ..Default::default()
588 }),
589 );
590 map.insert(
591 SmolStr::new_static("quote"),
592 LexUserType::Object(LexObject {
593 required: Some(
594 vec![SmolStr::new_static("start"), SmolStr::new_static("end")],
595 ),
596 properties: {
597 #[allow(unused_mut)]
598 let mut map = BTreeMap::new();
599 map.insert(
600 SmolStr::new_static("end"),
601 LexObjectProperty::Ref(LexRef {
602 r#ref: CowStr::new_static("#position"),
603 ..Default::default()
604 }),
605 );
606 map.insert(
607 SmolStr::new_static("start"),
608 LexObjectProperty::Ref(LexRef {
609 r#ref: CowStr::new_static("#position"),
610 ..Default::default()
611 }),
612 );
613 map
614 },
615 ..Default::default()
616 }),
617 );
618 map.insert(
619 SmolStr::new_static("textAlignCenter"),
620 LexUserType::Token(LexToken { ..Default::default() }),
621 );
622 map.insert(
623 SmolStr::new_static("textAlignLeft"),
624 LexUserType::Token(LexToken { ..Default::default() }),
625 );
626 map.insert(
627 SmolStr::new_static("textAlignRight"),
628 LexUserType::Token(LexToken { ..Default::default() }),
629 );
630 map
631 },
632 ..Default::default()
633 }
634}
635
636pub mod canvas_state {
637
638 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
639 #[allow(unused)]
640 use ::core::marker::PhantomData;
641 mod sealed {
642 pub trait Sealed {}
643 }
644 pub trait State: sealed::Sealed {
646 type Blocks;
647 }
648 pub struct Empty(());
650 impl sealed::Sealed for Empty {}
651 impl State for Empty {
652 type Blocks = Unset;
653 }
654 pub struct SetBlocks<S: State = Empty>(PhantomData<fn() -> S>);
656 impl<S: State> sealed::Sealed for SetBlocks<S> {}
657 impl<S: State> State for SetBlocks<S> {
658 type Blocks = Set<members::blocks>;
659 }
660 #[allow(non_camel_case_types)]
662 pub mod members {
663 pub struct blocks(());
665 }
666}
667
668pub struct CanvasBuilder<'a, S: canvas_state::State> {
670 _state: PhantomData<fn() -> S>,
671 _fields: (Option<Vec<canvas::Block<'a>>>, Option<CowStr<'a>>),
672 _lifetime: PhantomData<&'a ()>,
673}
674
675impl<'a> Canvas<'a> {
676 pub fn new() -> CanvasBuilder<'a, canvas_state::Empty> {
678 CanvasBuilder::new()
679 }
680}
681
682impl<'a> CanvasBuilder<'a, canvas_state::Empty> {
683 pub fn new() -> Self {
685 CanvasBuilder {
686 _state: PhantomData,
687 _fields: (None, None),
688 _lifetime: PhantomData,
689 }
690 }
691}
692
693impl<'a, S> CanvasBuilder<'a, S>
694where
695 S: canvas_state::State,
696 S::Blocks: canvas_state::IsUnset,
697{
698 pub fn blocks(
700 mut self,
701 value: impl Into<Vec<canvas::Block<'a>>>,
702 ) -> CanvasBuilder<'a, canvas_state::SetBlocks<S>> {
703 self._fields.0 = Option::Some(value.into());
704 CanvasBuilder {
705 _state: PhantomData,
706 _fields: self._fields,
707 _lifetime: PhantomData,
708 }
709 }
710}
711
712impl<'a, S: canvas_state::State> CanvasBuilder<'a, S> {
713 pub fn id(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
715 self._fields.1 = value.into();
716 self
717 }
718 pub fn maybe_id(mut self, value: Option<CowStr<'a>>) -> Self {
720 self._fields.1 = value;
721 self
722 }
723}
724
725impl<'a, S> CanvasBuilder<'a, S>
726where
727 S: canvas_state::State,
728 S::Blocks: canvas_state::IsSet,
729{
730 pub fn build(self) -> Canvas<'a> {
732 Canvas {
733 blocks: self._fields.0.unwrap(),
734 id: self._fields.1,
735 extra_data: Default::default(),
736 }
737 }
738 pub fn build_with_data(
740 self,
741 extra_data: BTreeMap<
742 jacquard_common::deps::smol_str::SmolStr,
743 jacquard_common::types::value::Data<'a>,
744 >,
745 ) -> Canvas<'a> {
746 Canvas {
747 blocks: self._fields.0.unwrap(),
748 id: self._fields.1,
749 extra_data: Some(extra_data),
750 }
751 }
752}
753
754pub mod position_state {
755
756 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
757 #[allow(unused)]
758 use ::core::marker::PhantomData;
759 mod sealed {
760 pub trait Sealed {}
761 }
762 pub trait State: sealed::Sealed {
764 type Block;
765 type Offset;
766 }
767 pub struct Empty(());
769 impl sealed::Sealed for Empty {}
770 impl State for Empty {
771 type Block = Unset;
772 type Offset = Unset;
773 }
774 pub struct SetBlock<S: State = Empty>(PhantomData<fn() -> S>);
776 impl<S: State> sealed::Sealed for SetBlock<S> {}
777 impl<S: State> State for SetBlock<S> {
778 type Block = Set<members::block>;
779 type Offset = S::Offset;
780 }
781 pub struct SetOffset<S: State = Empty>(PhantomData<fn() -> S>);
783 impl<S: State> sealed::Sealed for SetOffset<S> {}
784 impl<S: State> State for SetOffset<S> {
785 type Block = S::Block;
786 type Offset = Set<members::offset>;
787 }
788 #[allow(non_camel_case_types)]
790 pub mod members {
791 pub struct block(());
793 pub struct offset(());
795 }
796}
797
798pub struct PositionBuilder<'a, S: position_state::State> {
800 _state: PhantomData<fn() -> S>,
801 _fields: (Option<Vec<i64>>, Option<i64>),
802 _lifetime: PhantomData<&'a ()>,
803}
804
805impl<'a> Position<'a> {
806 pub fn new() -> PositionBuilder<'a, position_state::Empty> {
808 PositionBuilder::new()
809 }
810}
811
812impl<'a> PositionBuilder<'a, position_state::Empty> {
813 pub fn new() -> Self {
815 PositionBuilder {
816 _state: PhantomData,
817 _fields: (None, None),
818 _lifetime: PhantomData,
819 }
820 }
821}
822
823impl<'a, S> PositionBuilder<'a, S>
824where
825 S: position_state::State,
826 S::Block: position_state::IsUnset,
827{
828 pub fn block(
830 mut self,
831 value: impl Into<Vec<i64>>,
832 ) -> PositionBuilder<'a, position_state::SetBlock<S>> {
833 self._fields.0 = Option::Some(value.into());
834 PositionBuilder {
835 _state: PhantomData,
836 _fields: self._fields,
837 _lifetime: PhantomData,
838 }
839 }
840}
841
842impl<'a, S> PositionBuilder<'a, S>
843where
844 S: position_state::State,
845 S::Offset: position_state::IsUnset,
846{
847 pub fn offset(
849 mut self,
850 value: impl Into<i64>,
851 ) -> PositionBuilder<'a, position_state::SetOffset<S>> {
852 self._fields.1 = Option::Some(value.into());
853 PositionBuilder {
854 _state: PhantomData,
855 _fields: self._fields,
856 _lifetime: PhantomData,
857 }
858 }
859}
860
861impl<'a, S> PositionBuilder<'a, S>
862where
863 S: position_state::State,
864 S::Block: position_state::IsSet,
865 S::Offset: position_state::IsSet,
866{
867 pub fn build(self) -> Position<'a> {
869 Position {
870 block: self._fields.0.unwrap(),
871 offset: self._fields.1.unwrap(),
872 extra_data: Default::default(),
873 }
874 }
875 pub fn build_with_data(
877 self,
878 extra_data: BTreeMap<
879 jacquard_common::deps::smol_str::SmolStr,
880 jacquard_common::types::value::Data<'a>,
881 >,
882 ) -> Position<'a> {
883 Position {
884 block: self._fields.0.unwrap(),
885 offset: self._fields.1.unwrap(),
886 extra_data: Some(extra_data),
887 }
888 }
889}
890
891pub mod quote_state {
892
893 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
894 #[allow(unused)]
895 use ::core::marker::PhantomData;
896 mod sealed {
897 pub trait Sealed {}
898 }
899 pub trait State: sealed::Sealed {
901 type End;
902 type Start;
903 }
904 pub struct Empty(());
906 impl sealed::Sealed for Empty {}
907 impl State for Empty {
908 type End = Unset;
909 type Start = Unset;
910 }
911 pub struct SetEnd<S: State = Empty>(PhantomData<fn() -> S>);
913 impl<S: State> sealed::Sealed for SetEnd<S> {}
914 impl<S: State> State for SetEnd<S> {
915 type End = Set<members::end>;
916 type Start = S::Start;
917 }
918 pub struct SetStart<S: State = Empty>(PhantomData<fn() -> S>);
920 impl<S: State> sealed::Sealed for SetStart<S> {}
921 impl<S: State> State for SetStart<S> {
922 type End = S::End;
923 type Start = Set<members::start>;
924 }
925 #[allow(non_camel_case_types)]
927 pub mod members {
928 pub struct end(());
930 pub struct start(());
932 }
933}
934
935pub struct QuoteBuilder<'a, S: quote_state::State> {
937 _state: PhantomData<fn() -> S>,
938 _fields: (Option<canvas::Position<'a>>, Option<canvas::Position<'a>>),
939 _lifetime: PhantomData<&'a ()>,
940}
941
942impl<'a> Quote<'a> {
943 pub fn new() -> QuoteBuilder<'a, quote_state::Empty> {
945 QuoteBuilder::new()
946 }
947}
948
949impl<'a> QuoteBuilder<'a, quote_state::Empty> {
950 pub fn new() -> Self {
952 QuoteBuilder {
953 _state: PhantomData,
954 _fields: (None, None),
955 _lifetime: PhantomData,
956 }
957 }
958}
959
960impl<'a, S> QuoteBuilder<'a, S>
961where
962 S: quote_state::State,
963 S::End: quote_state::IsUnset,
964{
965 pub fn end(
967 mut self,
968 value: impl Into<canvas::Position<'a>>,
969 ) -> QuoteBuilder<'a, quote_state::SetEnd<S>> {
970 self._fields.0 = Option::Some(value.into());
971 QuoteBuilder {
972 _state: PhantomData,
973 _fields: self._fields,
974 _lifetime: PhantomData,
975 }
976 }
977}
978
979impl<'a, S> QuoteBuilder<'a, S>
980where
981 S: quote_state::State,
982 S::Start: quote_state::IsUnset,
983{
984 pub fn start(
986 mut self,
987 value: impl Into<canvas::Position<'a>>,
988 ) -> QuoteBuilder<'a, quote_state::SetStart<S>> {
989 self._fields.1 = Option::Some(value.into());
990 QuoteBuilder {
991 _state: PhantomData,
992 _fields: self._fields,
993 _lifetime: PhantomData,
994 }
995 }
996}
997
998impl<'a, S> QuoteBuilder<'a, S>
999where
1000 S: quote_state::State,
1001 S::End: quote_state::IsSet,
1002 S::Start: quote_state::IsSet,
1003{
1004 pub fn build(self) -> Quote<'a> {
1006 Quote {
1007 end: self._fields.0.unwrap(),
1008 start: self._fields.1.unwrap(),
1009 extra_data: Default::default(),
1010 }
1011 }
1012 pub fn build_with_data(
1014 self,
1015 extra_data: BTreeMap<
1016 jacquard_common::deps::smol_str::SmolStr,
1017 jacquard_common::types::value::Data<'a>,
1018 >,
1019 ) -> Quote<'a> {
1020 Quote {
1021 end: self._fields.0.unwrap(),
1022 start: self._fields.1.unwrap(),
1023 extra_data: Some(extra_data),
1024 }
1025 }
1026}