#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Work<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub id: std::option::Option<jacquard_common::CowStr<'a>>,
#[serde(borrow)]
pub title: jacquard_common::CowStr<'a>,
#[serde(borrow)]
pub work_type: WorkWorkType<'a>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
pub year: std::option::Option<i64>,
}
pub mod work_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 WorkType;
type Title;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type WorkType = Unset;
type Title = Unset;
}
pub struct SetWorkType<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetWorkType<S> {}
impl<S: State> State for SetWorkType<S> {
type WorkType = Set<members::work_type>;
type Title = S::Title;
}
pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTitle<S> {}
impl<S: State> State for SetTitle<S> {
type WorkType = S::WorkType;
type Title = Set<members::title>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct work_type(());
pub struct title(());
}
}
pub struct WorkBuilder<'a, S: work_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<WorkWorkType<'a>>,
::core::option::Option<i64>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Work<'a> {
pub fn new() -> WorkBuilder<'a, work_state::Empty> {
WorkBuilder::new()
}
}
impl<'a> WorkBuilder<'a, work_state::Empty> {
pub fn new() -> Self {
WorkBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: work_state::State> WorkBuilder<'a, S> {
pub fn id(mut self, value: impl Into<Option<jacquard_common::CowStr<'a>>>) -> Self {
self.__unsafe_private_named.0 = value.into();
self
}
pub fn maybe_id(mut self, value: Option<jacquard_common::CowStr<'a>>) -> Self {
self.__unsafe_private_named.0 = value;
self
}
}
impl<'a, S> WorkBuilder<'a, S>
where
S: work_state::State,
S::Title: work_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<jacquard_common::CowStr<'a>>,
) -> WorkBuilder<'a, work_state::SetTitle<S>> {
self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
WorkBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> WorkBuilder<'a, S>
where
S: work_state::State,
S::WorkType: work_state::IsUnset,
{
pub fn work_type(
mut self,
value: impl Into<WorkWorkType<'a>>,
) -> WorkBuilder<'a, work_state::SetWorkType<S>> {
self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
WorkBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: work_state::State> WorkBuilder<'a, S> {
pub fn year(mut self, value: impl Into<Option<i64>>) -> Self {
self.__unsafe_private_named.3 = value.into();
self
}
pub fn maybe_year(mut self, value: Option<i64>) -> Self {
self.__unsafe_private_named.3 = value;
self
}
}
impl<'a, S> WorkBuilder<'a, S>
where
S: work_state::State,
S::WorkType: work_state::IsSet,
S::Title: work_state::IsSet,
{
pub fn build(self) -> Work<'a> {
Work {
id: self.__unsafe_private_named.0,
title: self.__unsafe_private_named.1.unwrap(),
work_type: self.__unsafe_private_named.2.unwrap(),
year: self.__unsafe_private_named.3,
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>,
>,
) -> Work<'a> {
Work {
id: self.__unsafe_private_named.0,
title: self.__unsafe_private_named.1.unwrap(),
work_type: self.__unsafe_private_named.2.unwrap(),
year: self.__unsafe_private_named.3,
extra_data: Some(extra_data),
}
}
}
impl<'a> Work<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, WorkRecord>,
jacquard_common::types::uri::UriError,
> {
jacquard_common::types::uri::RecordUri::try_from_uri(
jacquard_common::types::string::AtUri::new_cow(uri.into())?,
)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WorkWorkType<'a> {
Movie,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> WorkWorkType<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::Movie => "Movie",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for WorkWorkType<'a> {
fn from(s: &'a str) -> Self {
match s {
"Movie" => Self::Movie,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for WorkWorkType<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"Movie" => Self::Movie,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for WorkWorkType<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for WorkWorkType<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for WorkWorkType<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for WorkWorkType<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for WorkWorkType<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for WorkWorkType<'_> {
type Output = WorkWorkType<'static>;
fn into_static(self) -> Self::Output {
match self {
WorkWorkType::Movie => WorkWorkType::Movie,
WorkWorkType::Other(v) => WorkWorkType::Other(v.into_static()),
}
}
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct WorkGetRecordOutput<'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: Work<'a>,
}
impl From<WorkGetRecordOutput<'_>> for Work<'_> {
fn from(output: WorkGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Work<'_> {
const NSID: &'static str = "social.lexical.works.work";
type Record = WorkRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct WorkRecord;
impl jacquard_common::xrpc::XrpcResp for WorkRecord {
const NSID: &'static str = "social.lexical.works.work";
const ENCODING: &'static str = "application/json";
type Output<'de> = WorkGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for WorkRecord {
const NSID: &'static str = "social.lexical.works.work";
type Record = WorkRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Work<'a> {
fn nsid() -> &'static str {
"social.lexical.works.work"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_social_lexical_works_work()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
if let Some(ref value) = self.id {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"id",
),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.id {
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 32usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"id",
),
max: 32usize,
actual: count,
});
}
}
}
{
let value = &self.title;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1024usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 1024usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.title;
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 512usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"title",
),
max: 512usize,
actual: count,
});
}
}
}
{
let value = &self.work_type;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 128usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"work_type",
),
max: 128usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.work_type;
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 64usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"work_type",
),
max: 64usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.year {
if *value > 2199i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Maximum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"year",
),
max: 2199i64,
actual: *value,
});
}
}
if let Some(ref value) = self.year {
if *value < 0i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"year",
),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
fn lexicon_doc_social_lexical_works_work() -> ::jacquard_lexicon::lexicon::LexiconDoc<
'static,
> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("social.lexical.works.work"),
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("")),
key: Some(::jacquard_common::CowStr::new_static("any")),
record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
description: None,
required: Some(
vec![
::jacquard_common::deps::smol_str::SmolStr::new_static("title"),
::jacquard_common::deps::smol_str::SmolStr::new_static("workType")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"id",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(""),
),
format: None,
default: None,
min_length: None,
max_length: Some(64usize),
min_graphemes: None,
max_graphemes: Some(32usize),
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(""),
),
format: None,
default: None,
min_length: None,
max_length: Some(1024usize),
min_graphemes: None,
max_graphemes: Some(512usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"workType",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(""),
),
format: None,
default: None,
min_length: None,
max_length: Some(128usize),
min_graphemes: None,
max_graphemes: Some(64usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"year",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(0i64),
maximum: Some(2199i64),
r#enum: None,
r#const: None,
}),
);
map
},
}),
}),
);
map
},
}
}