1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
14
15#[allow(unused_imports)]
16use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
17use jacquard_common::deps::smol_str::SmolStr;
18use jacquard_common::types::blob::BlobRef;
19use jacquard_common::types::string::UriValue;
20use jacquard_common::types::value::Data;
21use jacquard_derive::IntoStatic;
22use jacquard_lexicon::lexicon::LexiconDoc;
23use jacquard_lexicon::schema::LexiconSchema;
24
25use crate::app_bsky::embed::AspectRatio;
26use crate::app_bsky::embed::gallery;
27#[allow(unused_imports)]
28use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
29use serde::{Deserialize, Serialize};
30
31#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
32#[serde(
33 rename_all = "camelCase",
34 bound(deserialize = "S: Deserialize<'de> + BosStr")
35)]
36pub struct Image<S: BosStr = DefaultStr> {
37 pub alt: S,
39 pub aspect_ratio: AspectRatio<S>,
40 pub image: BlobRef<S>,
41 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
42 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
43}
44
45#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
46#[serde(
47 rename_all = "camelCase",
48 bound(deserialize = "S: Deserialize<'de> + BosStr")
49)]
50pub struct Gallery<S: BosStr = DefaultStr> {
51 pub items: Vec<gallery::Image<S>>,
53 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
54 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
55}
56
57#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
58#[serde(
59 rename_all = "camelCase",
60 bound(deserialize = "S: Deserialize<'de> + BosStr")
61)]
62pub struct View<S: BosStr = DefaultStr> {
63 pub items: Vec<gallery::ViewImage<S>>,
64 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
65 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
66}
67
68#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
69#[serde(
70 rename_all = "camelCase",
71 bound(deserialize = "S: Deserialize<'de> + BosStr")
72)]
73pub struct ViewImage<S: BosStr = DefaultStr> {
74 pub alt: S,
76 pub aspect_ratio: AspectRatio<S>,
77 pub fullsize: UriValue<S>,
79 pub thumbnail: UriValue<S>,
81 #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
82 pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
83}
84
85impl<S: BosStr> LexiconSchema for Image<S> {
86 fn nsid() -> &'static str {
87 "app.bsky.embed.gallery"
88 }
89 fn def_name() -> &'static str {
90 "image"
91 }
92 fn lexicon_doc() -> LexiconDoc<'static> {
93 lexicon_doc_app_bsky_embed_gallery()
94 }
95 fn validate(&self) -> Result<(), ConstraintError> {
96 {
97 let value = &self.image;
98 {
99 let size = value.blob().size;
100 if size > 2000000usize {
101 return Err(ConstraintError::BlobTooLarge {
102 path: ValidationPath::from_field("image"),
103 max: 2000000usize,
104 actual: size,
105 });
106 }
107 }
108 }
109 {
110 let value = &self.image;
111 {
112 let mime = value.blob().mime_type.as_str();
113 let accepted: &[&str] = &["image/*"];
114 let matched = accepted.iter().any(|pattern| {
115 if *pattern == "*/*" {
116 true
117 } else if pattern.ends_with("/*") {
118 let prefix = &pattern[..pattern.len() - 2];
119 mime.starts_with(prefix) && mime.as_bytes().get(prefix.len()) == Some(&b'/')
120 } else {
121 mime == *pattern
122 }
123 });
124 if !matched {
125 return Err(ConstraintError::BlobMimeTypeNotAccepted {
126 path: ValidationPath::from_field("image"),
127 accepted: vec!["image/*".to_string()],
128 actual: mime.to_string(),
129 });
130 }
131 }
132 }
133 Ok(())
134 }
135}
136
137impl<S: BosStr> LexiconSchema for Gallery<S> {
138 fn nsid() -> &'static str {
139 "app.bsky.embed.gallery"
140 }
141 fn def_name() -> &'static str {
142 "main"
143 }
144 fn lexicon_doc() -> LexiconDoc<'static> {
145 lexicon_doc_app_bsky_embed_gallery()
146 }
147 fn validate(&self) -> Result<(), ConstraintError> {
148 {
149 let value = &self.items;
150 #[allow(unused_comparisons)]
151 if value.len() > 20usize {
152 return Err(ConstraintError::MaxLength {
153 path: ValidationPath::from_field("items"),
154 max: 20usize,
155 actual: value.len(),
156 });
157 }
158 }
159 Ok(())
160 }
161}
162
163impl<S: BosStr> LexiconSchema for View<S> {
164 fn nsid() -> &'static str {
165 "app.bsky.embed.gallery"
166 }
167 fn def_name() -> &'static str {
168 "view"
169 }
170 fn lexicon_doc() -> LexiconDoc<'static> {
171 lexicon_doc_app_bsky_embed_gallery()
172 }
173 fn validate(&self) -> Result<(), ConstraintError> {
174 Ok(())
175 }
176}
177
178impl<S: BosStr> LexiconSchema for ViewImage<S> {
179 fn nsid() -> &'static str {
180 "app.bsky.embed.gallery"
181 }
182 fn def_name() -> &'static str {
183 "viewImage"
184 }
185 fn lexicon_doc() -> LexiconDoc<'static> {
186 lexicon_doc_app_bsky_embed_gallery()
187 }
188 fn validate(&self) -> Result<(), ConstraintError> {
189 Ok(())
190 }
191}
192
193pub mod image_state {
194
195 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
196 #[allow(unused)]
197 use ::core::marker::PhantomData;
198 mod sealed {
199 pub trait Sealed {}
200 }
201 pub trait State: sealed::Sealed {
203 type Alt;
204 type AspectRatio;
205 type Image;
206 }
207 pub struct Empty(());
209 impl sealed::Sealed for Empty {}
210 impl State for Empty {
211 type Alt = Unset;
212 type AspectRatio = Unset;
213 type Image = Unset;
214 }
215 pub struct SetAlt<St: State = Empty>(PhantomData<fn() -> St>);
217 impl<St: State> sealed::Sealed for SetAlt<St> {}
218 impl<St: State> State for SetAlt<St> {
219 type Alt = Set<members::alt>;
220 type AspectRatio = St::AspectRatio;
221 type Image = St::Image;
222 }
223 pub struct SetAspectRatio<St: State = Empty>(PhantomData<fn() -> St>);
225 impl<St: State> sealed::Sealed for SetAspectRatio<St> {}
226 impl<St: State> State for SetAspectRatio<St> {
227 type Alt = St::Alt;
228 type AspectRatio = Set<members::aspect_ratio>;
229 type Image = St::Image;
230 }
231 pub struct SetImage<St: State = Empty>(PhantomData<fn() -> St>);
233 impl<St: State> sealed::Sealed for SetImage<St> {}
234 impl<St: State> State for SetImage<St> {
235 type Alt = St::Alt;
236 type AspectRatio = St::AspectRatio;
237 type Image = Set<members::image>;
238 }
239 #[allow(non_camel_case_types)]
241 pub mod members {
242 pub struct alt(());
244 pub struct aspect_ratio(());
246 pub struct image(());
248 }
249}
250
251pub struct ImageBuilder<St: image_state::State, S: BosStr = DefaultStr> {
253 _state: PhantomData<fn() -> St>,
254 _fields: (Option<S>, Option<AspectRatio<S>>, Option<BlobRef<S>>),
255 _type: PhantomData<fn() -> S>,
256}
257
258impl Image<DefaultStr> {
259 pub fn new() -> ImageBuilder<image_state::Empty, DefaultStr> {
261 ImageBuilder::new()
262 }
263}
264
265impl<S: BosStr> Image<S> {
266 pub fn builder() -> ImageBuilder<image_state::Empty, S> {
268 ImageBuilder::builder()
269 }
270}
271
272impl ImageBuilder<image_state::Empty, DefaultStr> {
273 pub fn new() -> Self {
275 ImageBuilder {
276 _state: PhantomData,
277 _fields: (None, None, None),
278 _type: PhantomData,
279 }
280 }
281}
282
283impl<S: BosStr> ImageBuilder<image_state::Empty, S> {
284 pub fn builder() -> Self {
286 ImageBuilder {
287 _state: PhantomData,
288 _fields: (None, None, None),
289 _type: PhantomData,
290 }
291 }
292}
293
294impl<St, S: BosStr> ImageBuilder<St, S>
295where
296 St: image_state::State,
297 St::Alt: image_state::IsUnset,
298{
299 pub fn alt(mut self, value: impl Into<S>) -> ImageBuilder<image_state::SetAlt<St>, S> {
301 self._fields.0 = Option::Some(value.into());
302 ImageBuilder {
303 _state: PhantomData,
304 _fields: self._fields,
305 _type: PhantomData,
306 }
307 }
308}
309
310impl<St, S: BosStr> ImageBuilder<St, S>
311where
312 St: image_state::State,
313 St::AspectRatio: image_state::IsUnset,
314{
315 pub fn aspect_ratio(
317 mut self,
318 value: impl Into<AspectRatio<S>>,
319 ) -> ImageBuilder<image_state::SetAspectRatio<St>, S> {
320 self._fields.1 = Option::Some(value.into());
321 ImageBuilder {
322 _state: PhantomData,
323 _fields: self._fields,
324 _type: PhantomData,
325 }
326 }
327}
328
329impl<St, S: BosStr> ImageBuilder<St, S>
330where
331 St: image_state::State,
332 St::Image: image_state::IsUnset,
333{
334 pub fn image(
336 mut self,
337 value: impl Into<BlobRef<S>>,
338 ) -> ImageBuilder<image_state::SetImage<St>, S> {
339 self._fields.2 = Option::Some(value.into());
340 ImageBuilder {
341 _state: PhantomData,
342 _fields: self._fields,
343 _type: PhantomData,
344 }
345 }
346}
347
348impl<St, S: BosStr> ImageBuilder<St, S>
349where
350 St: image_state::State,
351 St::Alt: image_state::IsSet,
352 St::AspectRatio: image_state::IsSet,
353 St::Image: image_state::IsSet,
354{
355 pub fn build(self) -> Image<S> {
357 Image {
358 alt: self._fields.0.unwrap(),
359 aspect_ratio: self._fields.1.unwrap(),
360 image: self._fields.2.unwrap(),
361 extra_data: Default::default(),
362 }
363 }
364 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Image<S> {
366 Image {
367 alt: self._fields.0.unwrap(),
368 aspect_ratio: self._fields.1.unwrap(),
369 image: self._fields.2.unwrap(),
370 extra_data: Some(extra_data),
371 }
372 }
373}
374
375fn lexicon_doc_app_bsky_embed_gallery() -> LexiconDoc<'static> {
376 use alloc::collections::BTreeMap;
377 #[allow(unused_imports)]
378 use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
379 use jacquard_lexicon::lexicon::*;
380 LexiconDoc {
381 lexicon: Lexicon::Lexicon1,
382 id: CowStr::new_static("app.bsky.embed.gallery"),
383 defs: {
384 let mut map = BTreeMap::new();
385 map.insert(
386 SmolStr::new_static("image"),
387 LexUserType::Object(LexObject {
388 required: Some(vec![
389 SmolStr::new_static("image"),
390 SmolStr::new_static("alt"),
391 SmolStr::new_static("aspectRatio"),
392 ]),
393 properties: {
394 #[allow(unused_mut)]
395 let mut map = BTreeMap::new();
396 map.insert(
397 SmolStr::new_static("alt"),
398 LexObjectProperty::String(LexString {
399 description: Some(CowStr::new_static(
400 "Alt text description of the image, for accessibility.",
401 )),
402 ..Default::default()
403 }),
404 );
405 map.insert(
406 SmolStr::new_static("aspectRatio"),
407 LexObjectProperty::Ref(LexRef {
408 r#ref: CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
409 ..Default::default()
410 }),
411 );
412 map.insert(
413 SmolStr::new_static("image"),
414 LexObjectProperty::Blob(LexBlob {
415 ..Default::default()
416 }),
417 );
418 map
419 },
420 ..Default::default()
421 }),
422 );
423 map.insert(
424 SmolStr::new_static("main"),
425 LexUserType::Object(LexObject {
426 required: Some(vec![SmolStr::new_static("items")]),
427 properties: {
428 #[allow(unused_mut)]
429 let mut map = BTreeMap::new();
430 map.insert(
431 SmolStr::new_static("items"),
432 LexObjectProperty::Array(LexArray {
433 description: Some(
434 CowStr::new_static(
435 "The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs.",
436 ),
437 ),
438 items: LexArrayItem::Union(LexRefUnion {
439 refs: vec![CowStr::new_static("#image")],
440 ..Default::default()
441 }),
442 max_length: Some(20usize),
443 ..Default::default()
444 }),
445 );
446 map
447 },
448 ..Default::default()
449 }),
450 );
451 map.insert(
452 SmolStr::new_static("view"),
453 LexUserType::Object(LexObject {
454 required: Some(vec![SmolStr::new_static("items")]),
455 properties: {
456 #[allow(unused_mut)]
457 let mut map = BTreeMap::new();
458 map.insert(
459 SmolStr::new_static("items"),
460 LexObjectProperty::Array(LexArray {
461 items: LexArrayItem::Union(LexRefUnion {
462 refs: vec![CowStr::new_static("#viewImage")],
463 ..Default::default()
464 }),
465 ..Default::default()
466 }),
467 );
468 map
469 },
470 ..Default::default()
471 }),
472 );
473 map.insert(
474 SmolStr::new_static("viewImage"),
475 LexUserType::Object(LexObject {
476 required: Some(
477 vec![
478 SmolStr::new_static("thumbnail"),
479 SmolStr::new_static("fullsize"), SmolStr::new_static("alt"),
480 SmolStr::new_static("aspectRatio")
481 ],
482 ),
483 properties: {
484 #[allow(unused_mut)]
485 let mut map = BTreeMap::new();
486 map.insert(
487 SmolStr::new_static("alt"),
488 LexObjectProperty::String(LexString {
489 description: Some(
490 CowStr::new_static(
491 "Alt text description of the image, for accessibility.",
492 ),
493 ),
494 ..Default::default()
495 }),
496 );
497 map.insert(
498 SmolStr::new_static("aspectRatio"),
499 LexObjectProperty::Ref(LexRef {
500 r#ref: CowStr::new_static(
501 "app.bsky.embed.defs#aspectRatio",
502 ),
503 ..Default::default()
504 }),
505 );
506 map.insert(
507 SmolStr::new_static("fullsize"),
508 LexObjectProperty::String(LexString {
509 description: Some(
510 CowStr::new_static(
511 "Fully-qualified URL where a large version of the image can be fetched. May or may not be the exact original blob. For example, CDN location provided by the App View.",
512 ),
513 ),
514 format: Some(LexStringFormat::Uri),
515 ..Default::default()
516 }),
517 );
518 map.insert(
519 SmolStr::new_static("thumbnail"),
520 LexObjectProperty::String(LexString {
521 description: Some(
522 CowStr::new_static(
523 "Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View.",
524 ),
525 ),
526 format: Some(LexStringFormat::Uri),
527 ..Default::default()
528 }),
529 );
530 map
531 },
532 ..Default::default()
533 }),
534 );
535 map
536 },
537 ..Default::default()
538 }
539}
540
541pub mod gallery_state {
542
543 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
544 #[allow(unused)]
545 use ::core::marker::PhantomData;
546 mod sealed {
547 pub trait Sealed {}
548 }
549 pub trait State: sealed::Sealed {
551 type Items;
552 }
553 pub struct Empty(());
555 impl sealed::Sealed for Empty {}
556 impl State for Empty {
557 type Items = Unset;
558 }
559 pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
561 impl<St: State> sealed::Sealed for SetItems<St> {}
562 impl<St: State> State for SetItems<St> {
563 type Items = Set<members::items>;
564 }
565 #[allow(non_camel_case_types)]
567 pub mod members {
568 pub struct items(());
570 }
571}
572
573pub struct GalleryBuilder<St: gallery_state::State, S: BosStr = DefaultStr> {
575 _state: PhantomData<fn() -> St>,
576 _fields: (Option<Vec<gallery::Image<S>>>,),
577 _type: PhantomData<fn() -> S>,
578}
579
580impl Gallery<DefaultStr> {
581 pub fn new() -> GalleryBuilder<gallery_state::Empty, DefaultStr> {
583 GalleryBuilder::new()
584 }
585}
586
587impl<S: BosStr> Gallery<S> {
588 pub fn builder() -> GalleryBuilder<gallery_state::Empty, S> {
590 GalleryBuilder::builder()
591 }
592}
593
594impl GalleryBuilder<gallery_state::Empty, DefaultStr> {
595 pub fn new() -> Self {
597 GalleryBuilder {
598 _state: PhantomData,
599 _fields: (None,),
600 _type: PhantomData,
601 }
602 }
603}
604
605impl<S: BosStr> GalleryBuilder<gallery_state::Empty, S> {
606 pub fn builder() -> Self {
608 GalleryBuilder {
609 _state: PhantomData,
610 _fields: (None,),
611 _type: PhantomData,
612 }
613 }
614}
615
616impl<St, S: BosStr> GalleryBuilder<St, S>
617where
618 St: gallery_state::State,
619 St::Items: gallery_state::IsUnset,
620{
621 pub fn items(
623 mut self,
624 value: impl Into<Vec<gallery::Image<S>>>,
625 ) -> GalleryBuilder<gallery_state::SetItems<St>, S> {
626 self._fields.0 = Option::Some(value.into());
627 GalleryBuilder {
628 _state: PhantomData,
629 _fields: self._fields,
630 _type: PhantomData,
631 }
632 }
633}
634
635impl<St, S: BosStr> GalleryBuilder<St, S>
636where
637 St: gallery_state::State,
638 St::Items: gallery_state::IsSet,
639{
640 pub fn build(self) -> Gallery<S> {
642 Gallery {
643 items: self._fields.0.unwrap(),
644 extra_data: Default::default(),
645 }
646 }
647 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Gallery<S> {
649 Gallery {
650 items: self._fields.0.unwrap(),
651 extra_data: Some(extra_data),
652 }
653 }
654}
655
656pub mod view_state {
657
658 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
659 #[allow(unused)]
660 use ::core::marker::PhantomData;
661 mod sealed {
662 pub trait Sealed {}
663 }
664 pub trait State: sealed::Sealed {
666 type Items;
667 }
668 pub struct Empty(());
670 impl sealed::Sealed for Empty {}
671 impl State for Empty {
672 type Items = Unset;
673 }
674 pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
676 impl<St: State> sealed::Sealed for SetItems<St> {}
677 impl<St: State> State for SetItems<St> {
678 type Items = Set<members::items>;
679 }
680 #[allow(non_camel_case_types)]
682 pub mod members {
683 pub struct items(());
685 }
686}
687
688pub struct ViewBuilder<St: view_state::State, S: BosStr = DefaultStr> {
690 _state: PhantomData<fn() -> St>,
691 _fields: (Option<Vec<gallery::ViewImage<S>>>,),
692 _type: PhantomData<fn() -> S>,
693}
694
695impl View<DefaultStr> {
696 pub fn new() -> ViewBuilder<view_state::Empty, DefaultStr> {
698 ViewBuilder::new()
699 }
700}
701
702impl<S: BosStr> View<S> {
703 pub fn builder() -> ViewBuilder<view_state::Empty, S> {
705 ViewBuilder::builder()
706 }
707}
708
709impl ViewBuilder<view_state::Empty, DefaultStr> {
710 pub fn new() -> Self {
712 ViewBuilder {
713 _state: PhantomData,
714 _fields: (None,),
715 _type: PhantomData,
716 }
717 }
718}
719
720impl<S: BosStr> ViewBuilder<view_state::Empty, S> {
721 pub fn builder() -> Self {
723 ViewBuilder {
724 _state: PhantomData,
725 _fields: (None,),
726 _type: PhantomData,
727 }
728 }
729}
730
731impl<St, S: BosStr> ViewBuilder<St, S>
732where
733 St: view_state::State,
734 St::Items: view_state::IsUnset,
735{
736 pub fn items(
738 mut self,
739 value: impl Into<Vec<gallery::ViewImage<S>>>,
740 ) -> ViewBuilder<view_state::SetItems<St>, S> {
741 self._fields.0 = Option::Some(value.into());
742 ViewBuilder {
743 _state: PhantomData,
744 _fields: self._fields,
745 _type: PhantomData,
746 }
747 }
748}
749
750impl<St, S: BosStr> ViewBuilder<St, S>
751where
752 St: view_state::State,
753 St::Items: view_state::IsSet,
754{
755 pub fn build(self) -> View<S> {
757 View {
758 items: self._fields.0.unwrap(),
759 extra_data: Default::default(),
760 }
761 }
762 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> View<S> {
764 View {
765 items: self._fields.0.unwrap(),
766 extra_data: Some(extra_data),
767 }
768 }
769}
770
771pub mod view_image_state {
772
773 pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
774 #[allow(unused)]
775 use ::core::marker::PhantomData;
776 mod sealed {
777 pub trait Sealed {}
778 }
779 pub trait State: sealed::Sealed {
781 type Alt;
782 type AspectRatio;
783 type Fullsize;
784 type Thumbnail;
785 }
786 pub struct Empty(());
788 impl sealed::Sealed for Empty {}
789 impl State for Empty {
790 type Alt = Unset;
791 type AspectRatio = Unset;
792 type Fullsize = Unset;
793 type Thumbnail = Unset;
794 }
795 pub struct SetAlt<St: State = Empty>(PhantomData<fn() -> St>);
797 impl<St: State> sealed::Sealed for SetAlt<St> {}
798 impl<St: State> State for SetAlt<St> {
799 type Alt = Set<members::alt>;
800 type AspectRatio = St::AspectRatio;
801 type Fullsize = St::Fullsize;
802 type Thumbnail = St::Thumbnail;
803 }
804 pub struct SetAspectRatio<St: State = Empty>(PhantomData<fn() -> St>);
806 impl<St: State> sealed::Sealed for SetAspectRatio<St> {}
807 impl<St: State> State for SetAspectRatio<St> {
808 type Alt = St::Alt;
809 type AspectRatio = Set<members::aspect_ratio>;
810 type Fullsize = St::Fullsize;
811 type Thumbnail = St::Thumbnail;
812 }
813 pub struct SetFullsize<St: State = Empty>(PhantomData<fn() -> St>);
815 impl<St: State> sealed::Sealed for SetFullsize<St> {}
816 impl<St: State> State for SetFullsize<St> {
817 type Alt = St::Alt;
818 type AspectRatio = St::AspectRatio;
819 type Fullsize = Set<members::fullsize>;
820 type Thumbnail = St::Thumbnail;
821 }
822 pub struct SetThumbnail<St: State = Empty>(PhantomData<fn() -> St>);
824 impl<St: State> sealed::Sealed for SetThumbnail<St> {}
825 impl<St: State> State for SetThumbnail<St> {
826 type Alt = St::Alt;
827 type AspectRatio = St::AspectRatio;
828 type Fullsize = St::Fullsize;
829 type Thumbnail = Set<members::thumbnail>;
830 }
831 #[allow(non_camel_case_types)]
833 pub mod members {
834 pub struct alt(());
836 pub struct aspect_ratio(());
838 pub struct fullsize(());
840 pub struct thumbnail(());
842 }
843}
844
845pub struct ViewImageBuilder<St: view_image_state::State, S: BosStr = DefaultStr> {
847 _state: PhantomData<fn() -> St>,
848 _fields: (
849 Option<S>,
850 Option<AspectRatio<S>>,
851 Option<UriValue<S>>,
852 Option<UriValue<S>>,
853 ),
854 _type: PhantomData<fn() -> S>,
855}
856
857impl ViewImage<DefaultStr> {
858 pub fn new() -> ViewImageBuilder<view_image_state::Empty, DefaultStr> {
860 ViewImageBuilder::new()
861 }
862}
863
864impl<S: BosStr> ViewImage<S> {
865 pub fn builder() -> ViewImageBuilder<view_image_state::Empty, S> {
867 ViewImageBuilder::builder()
868 }
869}
870
871impl ViewImageBuilder<view_image_state::Empty, DefaultStr> {
872 pub fn new() -> Self {
874 ViewImageBuilder {
875 _state: PhantomData,
876 _fields: (None, None, None, None),
877 _type: PhantomData,
878 }
879 }
880}
881
882impl<S: BosStr> ViewImageBuilder<view_image_state::Empty, S> {
883 pub fn builder() -> Self {
885 ViewImageBuilder {
886 _state: PhantomData,
887 _fields: (None, None, None, None),
888 _type: PhantomData,
889 }
890 }
891}
892
893impl<St, S: BosStr> ViewImageBuilder<St, S>
894where
895 St: view_image_state::State,
896 St::Alt: view_image_state::IsUnset,
897{
898 pub fn alt(mut self, value: impl Into<S>) -> ViewImageBuilder<view_image_state::SetAlt<St>, S> {
900 self._fields.0 = Option::Some(value.into());
901 ViewImageBuilder {
902 _state: PhantomData,
903 _fields: self._fields,
904 _type: PhantomData,
905 }
906 }
907}
908
909impl<St, S: BosStr> ViewImageBuilder<St, S>
910where
911 St: view_image_state::State,
912 St::AspectRatio: view_image_state::IsUnset,
913{
914 pub fn aspect_ratio(
916 mut self,
917 value: impl Into<AspectRatio<S>>,
918 ) -> ViewImageBuilder<view_image_state::SetAspectRatio<St>, S> {
919 self._fields.1 = Option::Some(value.into());
920 ViewImageBuilder {
921 _state: PhantomData,
922 _fields: self._fields,
923 _type: PhantomData,
924 }
925 }
926}
927
928impl<St, S: BosStr> ViewImageBuilder<St, S>
929where
930 St: view_image_state::State,
931 St::Fullsize: view_image_state::IsUnset,
932{
933 pub fn fullsize(
935 mut self,
936 value: impl Into<UriValue<S>>,
937 ) -> ViewImageBuilder<view_image_state::SetFullsize<St>, S> {
938 self._fields.2 = Option::Some(value.into());
939 ViewImageBuilder {
940 _state: PhantomData,
941 _fields: self._fields,
942 _type: PhantomData,
943 }
944 }
945}
946
947impl<St, S: BosStr> ViewImageBuilder<St, S>
948where
949 St: view_image_state::State,
950 St::Thumbnail: view_image_state::IsUnset,
951{
952 pub fn thumbnail(
954 mut self,
955 value: impl Into<UriValue<S>>,
956 ) -> ViewImageBuilder<view_image_state::SetThumbnail<St>, S> {
957 self._fields.3 = Option::Some(value.into());
958 ViewImageBuilder {
959 _state: PhantomData,
960 _fields: self._fields,
961 _type: PhantomData,
962 }
963 }
964}
965
966impl<St, S: BosStr> ViewImageBuilder<St, S>
967where
968 St: view_image_state::State,
969 St::Alt: view_image_state::IsSet,
970 St::AspectRatio: view_image_state::IsSet,
971 St::Fullsize: view_image_state::IsSet,
972 St::Thumbnail: view_image_state::IsSet,
973{
974 pub fn build(self) -> ViewImage<S> {
976 ViewImage {
977 alt: self._fields.0.unwrap(),
978 aspect_ratio: self._fields.1.unwrap(),
979 fullsize: self._fields.2.unwrap(),
980 thumbnail: self._fields.3.unwrap(),
981 extra_data: Default::default(),
982 }
983 }
984 pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ViewImage<S> {
986 ViewImage {
987 alt: self._fields.0.unwrap(),
988 aspect_ratio: self._fields.1.unwrap(),
989 fullsize: self._fields.2.unwrap(),
990 thumbnail: self._fields.3.unwrap(),
991 extra_data: Some(extra_data),
992 }
993 }
994}