#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Button<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub alt: std::option::Option<jacquard_common::CowStr<'a>>,
#[serde(borrow)]
pub blob: jacquard_common::types::blob::BlobRef<'a>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub href: std::option::Option<jacquard_common::CowStr<'a>>,
pub posted_at: jacquard_common::types::string::Datetime,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub title: std::option::Option<jacquard_common::CowStr<'a>>,
}
pub mod button_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 Blob;
type PostedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Blob = Unset;
type PostedAt = Unset;
}
pub struct SetBlob<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetBlob<S> {}
impl<S: State> State for SetBlob<S> {
type Blob = Set<members::blob>;
type PostedAt = S::PostedAt;
}
pub struct SetPostedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPostedAt<S> {}
impl<S: State> State for SetPostedAt<S> {
type Blob = S::Blob;
type PostedAt = Set<members::posted_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct blob(());
pub struct posted_at(());
}
}
pub struct ButtonBuilder<'a, S: button_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<jacquard_common::types::blob::BlobRef<'a>>,
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<jacquard_common::CowStr<'a>>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Button<'a> {
pub fn new() -> ButtonBuilder<'a, button_state::Empty> {
ButtonBuilder::new()
}
}
impl<'a> ButtonBuilder<'a, button_state::Empty> {
pub fn new() -> Self {
ButtonBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: button_state::State> ButtonBuilder<'a, S> {
pub fn alt(mut self, value: impl Into<Option<jacquard_common::CowStr<'a>>>) -> Self {
self.__unsafe_private_named.0 = value.into();
self
}
pub fn maybe_alt(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
self.__unsafe_private_named.0 = value;
self
}
}
impl<'a, S> ButtonBuilder<'a, S>
where
S: button_state::State,
S::Blob: button_state::IsUnset,
{
pub fn blob(
mut self,
value: impl Into<jacquard_common::types::blob::BlobRef<'a>>,
) -> ButtonBuilder<'a, button_state::SetBlob<S>> {
self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
ButtonBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: button_state::State> ButtonBuilder<'a, S> {
pub fn href(
mut self,
value: impl Into<Option<jacquard_common::CowStr<'a>>>,
) -> Self {
self.__unsafe_private_named.2 = value.into();
self
}
pub fn maybe_href(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
self.__unsafe_private_named.2 = value;
self
}
}
impl<'a, S> ButtonBuilder<'a, S>
where
S: button_state::State,
S::PostedAt: button_state::IsUnset,
{
pub fn posted_at(
mut self,
value: impl Into<jacquard_common::types::string::Datetime>,
) -> ButtonBuilder<'a, button_state::SetPostedAt<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
ButtonBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: button_state::State> ButtonBuilder<'a, S> {
pub fn title(
mut self,
value: impl Into<Option<jacquard_common::CowStr<'a>>>,
) -> Self {
self.__unsafe_private_named.4 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
self.__unsafe_private_named.4 = value;
self
}
}
impl<'a, S> ButtonBuilder<'a, S>
where
S: button_state::State,
S::Blob: button_state::IsSet,
S::PostedAt: button_state::IsSet,
{
pub fn build(self) -> Button<'a> {
Button {
alt: self.__unsafe_private_named.0,
blob: self.__unsafe_private_named.1.unwrap(),
href: self.__unsafe_private_named.2,
posted_at: self.__unsafe_private_named.3.unwrap(),
title: self.__unsafe_private_named.4,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: std::collections::BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Button<'a> {
Button {
alt: self.__unsafe_private_named.0,
blob: self.__unsafe_private_named.1.unwrap(),
href: self.__unsafe_private_named.2,
posted_at: self.__unsafe_private_named.3.unwrap(),
title: self.__unsafe_private_named.4,
extra_data: Some(extra_data),
}
}
}
impl<'a> Button<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, ButtonRecord>,
jacquard_common::types::uri::UriError,
> {
jacquard_common::types::uri::RecordUri::try_from_uri(
jacquard_common::types::string::AtUri::new_cow(uri.into())?,
)
}
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct ButtonGetRecordOutput<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::AtUri<'a>,
#[serde(borrow)]
pub value: Button<'a>,
}
impl From<ButtonGetRecordOutput<'_>> for Button<'_> {
fn from(output: ButtonGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Button<'_> {
const NSID: &'static str = "store.88x31.button";
type Record = ButtonRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct ButtonRecord;
impl jacquard_common::xrpc::XrpcResp for ButtonRecord {
const NSID: &'static str = "store.88x31.button";
const ENCODING: &'static str = "application/json";
type Output<'de> = ButtonGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for ButtonRecord {
const NSID: &'static str = "store.88x31.button";
type Record = ButtonRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Button<'a> {
fn nsid() -> &'static str {
"store.88x31.button"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_store_88x31_button()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
if let Some(ref value) = self.alt {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"alt",
),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.alt {
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 300usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"alt",
),
max: 300usize,
actual: count,
});
}
}
}
{
let value = &self.blob;
{
let size = value.blob().size;
if size > 1000000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::BlobTooLarge {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"blob",
),
max: 1000000usize,
actual: size,
});
}
}
}
{
let value = &self.blob;
{
let mime = value.blob().mime_type.as_str();
let accepted: &[&str] = &["image/*"];
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(::jacquard_lexicon::validation::ConstraintError::BlobMimeTypeNotAccepted {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"blob",
),
accepted: vec!["image/*".to_string()],
actual: mime.to_string(),
});
}
}
}
if let Some(ref value) = self.href {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"href",
),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.href {
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 300usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"href",
),
max: 300usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.title {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 3000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 3000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.title {
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 300usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 300usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn lexicon_doc_store_88x31_button() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("store.88x31.button"),
revision: None,
description: None,
defs: {
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
description: Some(
::jacquard_common::CowStr::new_static(
"Record containing an 88x31 button.",
),
),
key: Some(::jacquard_common::CowStr::new_static("tid")),
record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
description: None,
required: Some(
vec![
::jacquard_common::deps::smol_str::SmolStr::new_static("blob"),
::jacquard_common::deps::smol_str::SmolStr::new_static("postedAt")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"alt",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"Alt text description of the button, for accessibility.",
),
),
format: None,
default: None,
min_length: None,
max_length: Some(3000usize),
min_graphemes: None,
max_graphemes: Some(300usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"blob",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Blob(::jacquard_lexicon::lexicon::LexBlob {
description: None,
accept: None,
max_size: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"href",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"Hypertext reference (link) for the button.",
),
),
format: None,
default: None,
min_length: None,
max_length: Some(3000usize),
min_graphemes: None,
max_graphemes: Some(300usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"postedAt",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"Client-declared timestamp when this button was originally created.",
),
),
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"title",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"Title text description of the button, for flavor.",
),
),
format: None,
default: None,
min_length: None,
max_length: Some(3000usize),
min_graphemes: None,
max_graphemes: Some(300usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map
},
}),
}),
);
map
},
}
}