#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Language};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::com_atproto::repo::strong_ref::StrongRef;
use crate::pub_quizzy::quiz;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Quiz<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub description: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_quiz_has_audio")]
pub has_audio: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_quiz_has_visuals")]
pub has_visuals: Option<bool>,
pub locales: Vec<Language>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub revision_of: Option<StrongRef<'a>>,
#[serde(borrow)]
pub rounds: Vec<quiz::Round<'a>>,
pub timestamp: Datetime,
#[serde(borrow)]
pub title: CowStr<'a>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct QuizGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Quiz<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct QuestionRef<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub name: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_question_ref_points")]
pub points: Option<i64>,
#[serde(borrow)]
pub question: StrongRef<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Round<'a> {
#[serde(borrow)]
pub questions: Vec<quiz::QuestionRef<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub title: Option<CowStr<'a>>,
}
impl<'a> Quiz<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, QuizRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QuizRecord;
impl XrpcResp for QuizRecord {
const NSID: &'static str = "pub.quizzy.quiz";
const ENCODING: &'static str = "application/json";
type Output<'de> = QuizGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<QuizGetRecordOutput<'_>> for Quiz<'_> {
fn from(output: QuizGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Quiz<'_> {
const NSID: &'static str = "pub.quizzy.quiz";
type Record = QuizRecord;
}
impl Collection for QuizRecord {
const NSID: &'static str = "pub.quizzy.quiz";
type Record = QuizRecord;
}
impl<'a> LexiconSchema for Quiz<'a> {
fn nsid() -> &'static str {
"pub.quizzy.quiz"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_quizzy_quiz()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.description {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 300usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("description"),
max: 300usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.description {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 3000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("description"),
max: 3000usize,
actual: count,
});
}
}
}
{
let value = &self.locales;
#[allow(unused_comparisons)]
if value.len() > 10usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("locales"),
max: 10usize,
actual: value.len(),
});
}
}
{
let value = &self.locales;
#[allow(unused_comparisons)]
if value.len() < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("locales"),
min: 1usize,
actual: value.len(),
});
}
}
{
let value = &self.rounds;
#[allow(unused_comparisons)]
if value.len() > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("rounds"),
max: 50usize,
actual: value.len(),
});
}
}
{
let value = &self.rounds;
#[allow(unused_comparisons)]
if value.len() < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("rounds"),
min: 1usize,
actual: value.len(),
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for QuestionRef<'a> {
fn nsid() -> &'static str {
"pub.quizzy.quiz"
}
fn def_name() -> &'static str {
"questionRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_quizzy_quiz()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 16usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("name"),
max: 16usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.name {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 160usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("name"),
max: 160usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.points {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("points"),
min: 1i64,
actual: *value,
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for Round<'a> {
fn nsid() -> &'static str {
"pub.quizzy.quiz"
}
fn def_name() -> &'static str {
"round"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_quizzy_quiz()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.questions;
#[allow(unused_comparisons)]
if value.len() > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("questions"),
max: 100usize,
actual: value.len(),
});
}
}
{
let value = &self.questions;
#[allow(unused_comparisons)]
if value.len() < 1usize {
return Err(ConstraintError::MinLength {
path: ValidationPath::from_field("questions"),
min: 1usize,
actual: value.len(),
});
}
}
if let Some(ref value) = self.title {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.title {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 100usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("title"),
max: 100usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn _default_quiz_has_audio() -> Option<bool> {
Some(false)
}
fn _default_quiz_has_visuals() -> Option<bool> {
Some(false)
}
pub mod quiz_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 Locales;
type Title;
type Timestamp;
type Rounds;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Locales = Unset;
type Title = Unset;
type Timestamp = Unset;
type Rounds = Unset;
}
pub struct SetLocales<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLocales<S> {}
impl<S: State> State for SetLocales<S> {
type Locales = Set<members::locales>;
type Title = S::Title;
type Timestamp = S::Timestamp;
type Rounds = S::Rounds;
}
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 Locales = S::Locales;
type Title = Set<members::title>;
type Timestamp = S::Timestamp;
type Rounds = S::Rounds;
}
pub struct SetTimestamp<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTimestamp<S> {}
impl<S: State> State for SetTimestamp<S> {
type Locales = S::Locales;
type Title = S::Title;
type Timestamp = Set<members::timestamp>;
type Rounds = S::Rounds;
}
pub struct SetRounds<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetRounds<S> {}
impl<S: State> State for SetRounds<S> {
type Locales = S::Locales;
type Title = S::Title;
type Timestamp = S::Timestamp;
type Rounds = Set<members::rounds>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct locales(());
pub struct title(());
pub struct timestamp(());
pub struct rounds(());
}
}
pub struct QuizBuilder<'a, S: quiz_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<CowStr<'a>>,
Option<bool>,
Option<bool>,
Option<Vec<Language>>,
Option<StrongRef<'a>>,
Option<Vec<quiz::Round<'a>>>,
Option<Datetime>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Quiz<'a> {
pub fn new() -> QuizBuilder<'a, quiz_state::Empty> {
QuizBuilder::new()
}
}
impl<'a> QuizBuilder<'a, quiz_state::Empty> {
pub fn new() -> Self {
QuizBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: quiz_state::State> QuizBuilder<'a, S> {
pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: quiz_state::State> QuizBuilder<'a, S> {
pub fn has_audio(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_has_audio(mut self, value: Option<bool>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: quiz_state::State> QuizBuilder<'a, S> {
pub fn has_visuals(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_has_visuals(mut self, value: Option<bool>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> QuizBuilder<'a, S>
where
S: quiz_state::State,
S::Locales: quiz_state::IsUnset,
{
pub fn locales(
mut self,
value: impl Into<Vec<Language>>,
) -> QuizBuilder<'a, quiz_state::SetLocales<S>> {
self._fields.3 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: quiz_state::State> QuizBuilder<'a, S> {
pub fn revision_of(mut self, value: impl Into<Option<StrongRef<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_revision_of(mut self, value: Option<StrongRef<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S> QuizBuilder<'a, S>
where
S: quiz_state::State,
S::Rounds: quiz_state::IsUnset,
{
pub fn rounds(
mut self,
value: impl Into<Vec<quiz::Round<'a>>>,
) -> QuizBuilder<'a, quiz_state::SetRounds<S>> {
self._fields.5 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> QuizBuilder<'a, S>
where
S: quiz_state::State,
S::Timestamp: quiz_state::IsUnset,
{
pub fn timestamp(
mut self,
value: impl Into<Datetime>,
) -> QuizBuilder<'a, quiz_state::SetTimestamp<S>> {
self._fields.6 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> QuizBuilder<'a, S>
where
S: quiz_state::State,
S::Title: quiz_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<CowStr<'a>>,
) -> QuizBuilder<'a, quiz_state::SetTitle<S>> {
self._fields.7 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> QuizBuilder<'a, S>
where
S: quiz_state::State,
S::Locales: quiz_state::IsSet,
S::Title: quiz_state::IsSet,
S::Timestamp: quiz_state::IsSet,
S::Rounds: quiz_state::IsSet,
{
pub fn build(self) -> Quiz<'a> {
Quiz {
description: self._fields.0,
has_audio: self._fields.1.or_else(|| Some(false)),
has_visuals: self._fields.2.or_else(|| Some(false)),
locales: self._fields.3.unwrap(),
revision_of: self._fields.4,
rounds: self._fields.5.unwrap(),
timestamp: self._fields.6.unwrap(),
title: self._fields.7.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Quiz<'a> {
Quiz {
description: self._fields.0,
has_audio: self._fields.1.or_else(|| Some(false)),
has_visuals: self._fields.2.or_else(|| Some(false)),
locales: self._fields.3.unwrap(),
revision_of: self._fields.4,
rounds: self._fields.5.unwrap(),
timestamp: self._fields.6.unwrap(),
title: self._fields.7.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_pub_quizzy_quiz() -> 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("pub.quizzy.quiz"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A quiz containing one or more rounds of questions",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("title"), SmolStr::new_static("rounds"),
SmolStr::new_static("locales"),
SmolStr::new_static("timestamp")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("description"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A short description about the quiz, and what to expect from it",
),
),
max_length: Some(300usize),
max_graphemes: Some(3000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("hasAudio"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("hasVisuals"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("locales"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Dominant language(s) of the quiz"),
),
items: LexArrayItem::String(LexString {
format: Some(LexStringFormat::Language),
..Default::default()
}),
min_length: Some(1usize),
max_length: Some(10usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("revisionOf"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rounds"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static("Ordered list of rounds in this quiz"),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#round"),
..Default::default()
}),
min_length: Some(1usize),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("timestamp"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When this quiz was created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("A title for the quiz"),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("questionRef"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Reference to a question with its point value",
),
),
required: Some(vec![SmolStr::new_static("question")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A custom name for this question, as opposed to its number",
),
),
max_length: Some(16usize),
max_graphemes: Some(160usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("points"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("question"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("round"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("A round within a quiz")),
required: Some(vec![SmolStr::new_static("questions")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("questions"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Ordered list of questions in this round",
),
),
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#questionRef"),
..Default::default()
}),
min_length: Some(1usize),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Optional title for this round (requires locale if set)",
),
),
max_length: Some(1000usize),
max_graphemes: Some(100usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
fn _default_question_ref_points() -> Option<i64> {
Some(1i64)
}
pub mod question_ref_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 Question;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Question = Unset;
}
pub struct SetQuestion<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetQuestion<S> {}
impl<S: State> State for SetQuestion<S> {
type Question = Set<members::question>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct question(());
}
}
pub struct QuestionRefBuilder<'a, S: question_ref_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<CowStr<'a>>, Option<i64>, Option<StrongRef<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> QuestionRef<'a> {
pub fn new() -> QuestionRefBuilder<'a, question_ref_state::Empty> {
QuestionRefBuilder::new()
}
}
impl<'a> QuestionRefBuilder<'a, question_ref_state::Empty> {
pub fn new() -> Self {
QuestionRefBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: question_ref_state::State> QuestionRefBuilder<'a, S> {
pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S: question_ref_state::State> QuestionRefBuilder<'a, S> {
pub fn points(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_points(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> QuestionRefBuilder<'a, S>
where
S: question_ref_state::State,
S::Question: question_ref_state::IsUnset,
{
pub fn question(
mut self,
value: impl Into<StrongRef<'a>>,
) -> QuestionRefBuilder<'a, question_ref_state::SetQuestion<S>> {
self._fields.2 = Option::Some(value.into());
QuestionRefBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> QuestionRefBuilder<'a, S>
where
S: question_ref_state::State,
S::Question: question_ref_state::IsSet,
{
pub fn build(self) -> QuestionRef<'a> {
QuestionRef {
name: self._fields.0,
points: self._fields.1.or_else(|| Some(1i64)),
question: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> QuestionRef<'a> {
QuestionRef {
name: self._fields.0,
points: self._fields.1.or_else(|| Some(1i64)),
question: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod round_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 Questions;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Questions = Unset;
}
pub struct SetQuestions<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetQuestions<S> {}
impl<S: State> State for SetQuestions<S> {
type Questions = Set<members::questions>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct questions(());
}
}
pub struct RoundBuilder<'a, S: round_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Vec<quiz::QuestionRef<'a>>>, Option<CowStr<'a>>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Round<'a> {
pub fn new() -> RoundBuilder<'a, round_state::Empty> {
RoundBuilder::new()
}
}
impl<'a> RoundBuilder<'a, round_state::Empty> {
pub fn new() -> Self {
RoundBuilder {
_state: PhantomData,
_fields: (None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> RoundBuilder<'a, S>
where
S: round_state::State,
S::Questions: round_state::IsUnset,
{
pub fn questions(
mut self,
value: impl Into<Vec<quiz::QuestionRef<'a>>>,
) -> RoundBuilder<'a, round_state::SetQuestions<S>> {
self._fields.0 = Option::Some(value.into());
RoundBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: round_state::State> RoundBuilder<'a, S> {
pub fn title(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S> RoundBuilder<'a, S>
where
S: round_state::State,
S::Questions: round_state::IsSet,
{
pub fn build(self) -> Round<'a> {
Round {
questions: self._fields.0.unwrap(),
title: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Round<'a> {
Round {
questions: self._fields.0.unwrap(),
title: self._fields.1,
extra_data: Some(extra_data),
}
}
}