#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::{Cid, Language, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::app_bsky::embed::AspectRatio;
use crate::sh_weaver::embed::PercentSize;
use crate::sh_weaver::embed::PixelSize;
use crate::sh_weaver::embed::video;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Caption<S: BosStr = DefaultStr> {
pub file: BlobRef<S>,
pub lang: Language,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct VideoRecord<S: BosStr = DefaultStr> {
pub videos: Vec<video::Video<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Video<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub alt: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub captions: Option<Vec<video::Caption<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<VideoDimensions<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
pub video: BlobRef<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum VideoDimensions<S: BosStr = DefaultStr> {
#[serde(rename = "app.bsky.embed.defs#aspectRatio")]
AspectRatio(Box<AspectRatio<S>>),
#[serde(rename = "sh.weaver.embed.defs#percentSize")]
PercentSize(Box<PercentSize<S>>),
#[serde(rename = "sh.weaver.embed.defs#pixelSize")]
PixelSize(Box<PixelSize<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct View<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub alt: Option<S>,
pub cid: Cid<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dimensions: Option<ViewDimensions<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
pub playlist: UriValue<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail: Option<UriValue<S>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ViewDimensions<S: BosStr = DefaultStr> {
#[serde(rename = "app.bsky.embed.defs#aspectRatio")]
AspectRatio(Box<AspectRatio<S>>),
#[serde(rename = "sh.weaver.embed.defs#percentSize")]
PercentSize(Box<PercentSize<S>>),
#[serde(rename = "sh.weaver.embed.defs#pixelSize")]
PixelSize(Box<PixelSize<S>>),
}
impl<S: BosStr> LexiconSchema for Caption<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.video"
}
fn def_name() -> &'static str {
"caption"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.file;
{
let size = value.blob().size;
if size > 20000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("file"),
max: 20000usize,
actual: size,
});
}
}
}
{
let value = &self.file;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["text/vtt"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("file"),
accepted: vec!["text/vtt".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for VideoRecord<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.video"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Video<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.video"
}
fn def_name() -> &'static str {
"video"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.alt {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("alt"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.alt {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("alt"),
max: 1000usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.captions {
#[allow(unused_comparisons)]
if value.len() > 20usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("captions"),
max: 20usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.video;
{
let size = value.blob().size;
if size > 100000000usize {
return Err(ConstraintError::BlobTooLarge {
path: ValidationPath::from_field("video"),
max: 100000000usize,
actual: size,
});
}
}
}
{
let value = &self.video;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["video/mp4"];
let matched = accepted
.iter()
.any(|pattern| {
if *pattern == "*/*" {
true
} else if pattern.ends_with("/*") {
let prefix = &pattern[..pattern.len() - 2];
mime.starts_with(prefix)
&& mime.as_bytes().get(prefix.len()) == Some(&b'/')
} else {
mime == *pattern
}
});
if !matched {
return Err(ConstraintError::BlobMimeTypeNotAccepted {
path: ValidationPath::from_field("video"),
accepted: vec!["video/mp4".to_string()],
actual: mime.to_string(),
});
}
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for View<S> {
fn nsid() -> &'static str {
"sh.weaver.embed.video"
}
fn def_name() -> &'static str {
"view"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_sh_weaver_embed_video()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.alt {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 10000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("alt"),
max: 10000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.alt {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("alt"),
max: 1000usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod caption_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type File;
type Lang;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type File = Unset;
type Lang = Unset;
}
pub struct SetFile<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetFile<St> {}
impl<St: State> State for SetFile<St> {
type File = Set<members::file>;
type Lang = St::Lang;
}
pub struct SetLang<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLang<St> {}
impl<St: State> State for SetLang<St> {
type File = St::File;
type Lang = Set<members::lang>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct file(());
pub struct lang(());
}
}
pub struct CaptionBuilder<S: BosStr, St: caption_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<BlobRef<S>>, Option<Language>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Caption<S> {
pub fn new() -> CaptionBuilder<S, caption_state::Empty> {
CaptionBuilder::new()
}
}
impl<S: BosStr> CaptionBuilder<S, caption_state::Empty> {
pub fn new() -> Self {
CaptionBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CaptionBuilder<S, St>
where
St: caption_state::State,
St::File: caption_state::IsUnset,
{
pub fn file(
mut self,
value: impl Into<BlobRef<S>>,
) -> CaptionBuilder<S, caption_state::SetFile<St>> {
self._fields.0 = Option::Some(value.into());
CaptionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CaptionBuilder<S, St>
where
St: caption_state::State,
St::Lang: caption_state::IsUnset,
{
pub fn lang(
mut self,
value: impl Into<Language>,
) -> CaptionBuilder<S, caption_state::SetLang<St>> {
self._fields.1 = Option::Some(value.into());
CaptionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CaptionBuilder<S, St>
where
St: caption_state::State,
St::File: caption_state::IsSet,
St::Lang: caption_state::IsSet,
{
pub fn build(self) -> Caption<S> {
Caption {
file: self._fields.0.unwrap(),
lang: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Caption<S> {
Caption {
file: self._fields.0.unwrap(),
lang: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_sh_weaver_embed_video() -> LexiconDoc<'static> {
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
use alloc::collections::BTreeMap;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("sh.weaver.embed.video"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("caption"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("lang"), SmolStr::new_static("file")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("file"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map.insert(
SmolStr::new_static("lang"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Language),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("videos")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("videos"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#video"),
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("video"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("video")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Alt text description of the video, for accessibility.",
),
),
max_length: Some(10000usize),
max_graphemes: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("captions"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#caption"),
..Default::default()
}),
max_length: Some(20usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("dimensions"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![
CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
CowStr::new_static("sh.weaver.embed.defs#percentSize"),
CowStr::new_static("sh.weaver.embed.defs#pixelSize")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("video"),
LexObjectProperty::Blob(LexBlob { ..Default::default() }),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("view"),
LexUserType::Object(LexObject {
required: Some(
vec![SmolStr::new_static("cid"), SmolStr::new_static("playlist")],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alt"),
LexObjectProperty::String(LexString {
max_length: Some(10000usize),
max_graphemes: Some(1000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("cid"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Cid),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("dimensions"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![
CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
CowStr::new_static("sh.weaver.embed.defs#percentSize"),
CowStr::new_static("sh.weaver.embed.defs#pixelSize")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
max_length: Some(128usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("playlist"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("thumbnail"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Uri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod video_record_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Videos;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Videos = Unset;
}
pub struct SetVideos<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetVideos<St> {}
impl<St: State> State for SetVideos<St> {
type Videos = Set<members::videos>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct videos(());
}
}
pub struct VideoRecordBuilder<S: BosStr, St: video_record_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<video::Video<S>>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> VideoRecord<S> {
pub fn new() -> VideoRecordBuilder<S, video_record_state::Empty> {
VideoRecordBuilder::new()
}
}
impl<S: BosStr> VideoRecordBuilder<S, video_record_state::Empty> {
pub fn new() -> Self {
VideoRecordBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideoRecordBuilder<S, St>
where
St: video_record_state::State,
St::Videos: video_record_state::IsUnset,
{
pub fn videos(
mut self,
value: impl Into<Vec<video::Video<S>>>,
) -> VideoRecordBuilder<S, video_record_state::SetVideos<St>> {
self._fields.0 = Option::Some(value.into());
VideoRecordBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideoRecordBuilder<S, St>
where
St: video_record_state::State,
St::Videos: video_record_state::IsSet,
{
pub fn build(self) -> VideoRecord<S> {
VideoRecord {
videos: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> VideoRecord<S> {
VideoRecord {
videos: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod video_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Video;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Video = Unset;
}
pub struct SetVideo<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetVideo<St> {}
impl<St: State> State for SetVideo<St> {
type Video = Set<members::video>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct video(());
}
}
pub struct VideoBuilder<S: BosStr, St: video_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Vec<video::Caption<S>>>,
Option<VideoDimensions<S>>,
Option<S>,
Option<BlobRef<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Video<S> {
pub fn new() -> VideoBuilder<S, video_state::Empty> {
VideoBuilder::new()
}
}
impl<S: BosStr> VideoBuilder<S, video_state::Empty> {
pub fn new() -> Self {
VideoBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: video_state::State> VideoBuilder<S, St> {
pub fn alt(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_alt(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: video_state::State> VideoBuilder<S, St> {
pub fn captions(mut self, value: impl Into<Option<Vec<video::Caption<S>>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_captions(mut self, value: Option<Vec<video::Caption<S>>>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: video_state::State> VideoBuilder<S, St> {
pub fn dimensions(mut self, value: impl Into<Option<VideoDimensions<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_dimensions(mut self, value: Option<VideoDimensions<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: video_state::State> VideoBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> VideoBuilder<S, St>
where
St: video_state::State,
St::Video: video_state::IsUnset,
{
pub fn video(
mut self,
value: impl Into<BlobRef<S>>,
) -> VideoBuilder<S, video_state::SetVideo<St>> {
self._fields.4 = Option::Some(value.into());
VideoBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> VideoBuilder<S, St>
where
St: video_state::State,
St::Video: video_state::IsSet,
{
pub fn build(self) -> Video<S> {
Video {
alt: self._fields.0,
captions: self._fields.1,
dimensions: self._fields.2,
name: self._fields.3,
video: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Video<S> {
Video {
alt: self._fields.0,
captions: self._fields.1,
dimensions: self._fields.2,
name: self._fields.3,
video: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod view_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Cid;
type Playlist;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Cid = Unset;
type Playlist = Unset;
}
pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCid<St> {}
impl<St: State> State for SetCid<St> {
type Cid = Set<members::cid>;
type Playlist = St::Playlist;
}
pub struct SetPlaylist<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPlaylist<St> {}
impl<St: State> State for SetPlaylist<St> {
type Cid = St::Cid;
type Playlist = Set<members::playlist>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct cid(());
pub struct playlist(());
}
}
pub struct ViewBuilder<S: BosStr, St: view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Cid<S>>,
Option<ViewDimensions<S>>,
Option<S>,
Option<UriValue<S>>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> View<S> {
pub fn new() -> ViewBuilder<S, view_state::Empty> {
ViewBuilder::new()
}
}
impl<S: BosStr> ViewBuilder<S, view_state::Empty> {
pub fn new() -> Self {
ViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: view_state::State> ViewBuilder<S, St> {
pub fn alt(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_alt(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> ViewBuilder<S, St>
where
St: view_state::State,
St::Cid: view_state::IsUnset,
{
pub fn cid(
mut self,
value: impl Into<Cid<S>>,
) -> ViewBuilder<S, view_state::SetCid<St>> {
self._fields.1 = Option::Some(value.into());
ViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: view_state::State> ViewBuilder<S, St> {
pub fn dimensions(mut self, value: impl Into<Option<ViewDimensions<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_dimensions(mut self, value: Option<ViewDimensions<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: view_state::State> ViewBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> ViewBuilder<S, St>
where
St: view_state::State,
St::Playlist: view_state::IsUnset,
{
pub fn playlist(
mut self,
value: impl Into<UriValue<S>>,
) -> ViewBuilder<S, view_state::SetPlaylist<St>> {
self._fields.4 = Option::Some(value.into());
ViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: view_state::State> ViewBuilder<S, St> {
pub fn thumbnail(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_thumbnail(mut self, value: Option<UriValue<S>>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St> ViewBuilder<S, St>
where
St: view_state::State,
St::Cid: view_state::IsSet,
St::Playlist: view_state::IsSet,
{
pub fn build(self) -> View<S> {
View {
alt: self._fields.0,
cid: self._fields.1.unwrap(),
dimensions: self._fields.2,
name: self._fields.3,
playlist: self._fields.4.unwrap(),
thumbnail: self._fields.5,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> View<S> {
View {
alt: self._fields.0,
cid: self._fields.1.unwrap(),
dimensions: self._fields.2,
name: self._fields.3,
playlist: self._fields.4.unwrap(),
thumbnail: self._fields.5,
extra_data: Some(extra_data),
}
}
}