#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Language};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
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;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "pub.quizzy.quiz",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Quiz<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
#[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")]
pub revision_of: Option<StrongRef<S>>,
pub rounds: Vec<quiz::Round<S>>,
pub timestamp: Datetime,
pub title: 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")]
pub struct QuizGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Quiz<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct QuestionRef<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_question_ref_points")]
pub points: Option<i64>,
pub question: StrongRef<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 Round<S: BosStr = DefaultStr> {
pub questions: Vec<quiz::QuestionRef<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub title: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Quiz<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, QuizRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[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<S: BosStr> = QuizGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<QuizGetRecordOutput<S>> for Quiz<S> {
fn from(output: QuizGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Quiz<S> {
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<S: BosStr> LexiconSchema for Quiz<S> {
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<S: BosStr> LexiconSchema for QuestionRef<S> {
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<S: BosStr> LexiconSchema for Round<S> {
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 Timestamp;
type Title;
type Rounds;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Locales = Unset;
type Timestamp = Unset;
type Title = Unset;
type Rounds = Unset;
}
pub struct SetLocales<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocales<St> {}
impl<St: State> State for SetLocales<St> {
type Locales = Set<members::locales>;
type Timestamp = St::Timestamp;
type Title = St::Title;
type Rounds = St::Rounds;
}
pub struct SetTimestamp<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTimestamp<St> {}
impl<St: State> State for SetTimestamp<St> {
type Locales = St::Locales;
type Timestamp = Set<members::timestamp>;
type Title = St::Title;
type Rounds = St::Rounds;
}
pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTitle<St> {}
impl<St: State> State for SetTitle<St> {
type Locales = St::Locales;
type Timestamp = St::Timestamp;
type Title = Set<members::title>;
type Rounds = St::Rounds;
}
pub struct SetRounds<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRounds<St> {}
impl<St: State> State for SetRounds<St> {
type Locales = St::Locales;
type Timestamp = St::Timestamp;
type Title = St::Title;
type Rounds = Set<members::rounds>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct locales(());
pub struct timestamp(());
pub struct title(());
pub struct rounds(());
}
}
pub struct QuizBuilder<S: BosStr, St: quiz_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<bool>,
Option<bool>,
Option<Vec<Language>>,
Option<StrongRef<S>>,
Option<Vec<quiz::Round<S>>>,
Option<Datetime>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Quiz<S> {
pub fn new() -> QuizBuilder<S, quiz_state::Empty> {
QuizBuilder::new()
}
}
impl<S: BosStr> QuizBuilder<S, quiz_state::Empty> {
pub fn new() -> Self {
QuizBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: quiz_state::State> QuizBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: quiz_state::State> QuizBuilder<S, St> {
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<S: BosStr, St: quiz_state::State> QuizBuilder<S, St> {
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<S: BosStr, St> QuizBuilder<S, St>
where
St: quiz_state::State,
St::Locales: quiz_state::IsUnset,
{
pub fn locales(
mut self,
value: impl Into<Vec<Language>>,
) -> QuizBuilder<S, quiz_state::SetLocales<St>> {
self._fields.3 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: quiz_state::State> QuizBuilder<S, St> {
pub fn revision_of(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_revision_of(mut self, value: Option<StrongRef<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> QuizBuilder<S, St>
where
St: quiz_state::State,
St::Rounds: quiz_state::IsUnset,
{
pub fn rounds(
mut self,
value: impl Into<Vec<quiz::Round<S>>>,
) -> QuizBuilder<S, quiz_state::SetRounds<St>> {
self._fields.5 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuizBuilder<S, St>
where
St: quiz_state::State,
St::Timestamp: quiz_state::IsUnset,
{
pub fn timestamp(
mut self,
value: impl Into<Datetime>,
) -> QuizBuilder<S, quiz_state::SetTimestamp<St>> {
self._fields.6 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuizBuilder<S, St>
where
St: quiz_state::State,
St::Title: quiz_state::IsUnset,
{
pub fn title(
mut self,
value: impl Into<S>,
) -> QuizBuilder<S, quiz_state::SetTitle<St>> {
self._fields.7 = Option::Some(value.into());
QuizBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuizBuilder<S, St>
where
St: quiz_state::State,
St::Locales: quiz_state::IsSet,
St::Timestamp: quiz_state::IsSet,
St::Title: quiz_state::IsSet,
St::Rounds: quiz_state::IsSet,
{
pub fn build(self) -> Quiz<S> {
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<SmolStr, Data<S>>) -> Quiz<S> {
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<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetQuestion<St> {}
impl<St: State> State for SetQuestion<St> {
type Question = Set<members::question>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct question(());
}
}
pub struct QuestionRefBuilder<S: BosStr, St: question_ref_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>, Option<i64>, Option<StrongRef<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> QuestionRef<S> {
pub fn new() -> QuestionRefBuilder<S, question_ref_state::Empty> {
QuestionRefBuilder::new()
}
}
impl<S: BosStr> QuestionRefBuilder<S, question_ref_state::Empty> {
pub fn new() -> Self {
QuestionRefBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: question_ref_state::State> QuestionRefBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: question_ref_state::State> QuestionRefBuilder<S, St> {
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<S: BosStr, St> QuestionRefBuilder<S, St>
where
St: question_ref_state::State,
St::Question: question_ref_state::IsUnset,
{
pub fn question(
mut self,
value: impl Into<StrongRef<S>>,
) -> QuestionRefBuilder<S, question_ref_state::SetQuestion<St>> {
self._fields.2 = Option::Some(value.into());
QuestionRefBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuestionRefBuilder<S, St>
where
St: question_ref_state::State,
St::Question: question_ref_state::IsSet,
{
pub fn build(self) -> QuestionRef<S> {
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<SmolStr, Data<S>>,
) -> QuestionRef<S> {
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<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetQuestions<St> {}
impl<St: State> State for SetQuestions<St> {
type Questions = Set<members::questions>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct questions(());
}
}
pub struct RoundBuilder<S: BosStr, St: round_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<quiz::QuestionRef<S>>>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Round<S> {
pub fn new() -> RoundBuilder<S, round_state::Empty> {
RoundBuilder::new()
}
}
impl<S: BosStr> RoundBuilder<S, round_state::Empty> {
pub fn new() -> Self {
RoundBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> RoundBuilder<S, St>
where
St: round_state::State,
St::Questions: round_state::IsUnset,
{
pub fn questions(
mut self,
value: impl Into<Vec<quiz::QuestionRef<S>>>,
) -> RoundBuilder<S, round_state::SetQuestions<St>> {
self._fields.0 = Option::Some(value.into());
RoundBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: round_state::State> RoundBuilder<S, St> {
pub fn title(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> RoundBuilder<S, St>
where
St: round_state::State,
St::Questions: round_state::IsSet,
{
pub fn build(self) -> Round<S> {
Round {
questions: self._fields.0.unwrap(),
title: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Round<S> {
Round {
questions: self._fields.0.unwrap(),
title: self._fields.1,
extra_data: Some(extra_data),
}
}
}