#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Answer<'a> {
#[serde(borrow)]
pub certainty: AnswerCertainty<'a>,
#[serde(borrow)]
pub question: crate::com_atproto::repo::strong_ref::StrongRef<'a>,
#[serde(borrow)]
pub text: jacquard_common::CowStr<'a>,
pub timestamp: jacquard_common::types::string::Datetime,
}
pub mod answer_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;
type Certainty;
type Text;
type Timestamp;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Question = Unset;
type Certainty = Unset;
type Text = Unset;
type Timestamp = 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>;
type Certainty = S::Certainty;
type Text = S::Text;
type Timestamp = S::Timestamp;
}
pub struct SetCertainty<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCertainty<S> {}
impl<S: State> State for SetCertainty<S> {
type Question = S::Question;
type Certainty = Set<members::certainty>;
type Text = S::Text;
type Timestamp = S::Timestamp;
}
pub struct SetText<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetText<S> {}
impl<S: State> State for SetText<S> {
type Question = S::Question;
type Certainty = S::Certainty;
type Text = Set<members::text>;
type Timestamp = S::Timestamp;
}
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 Question = S::Question;
type Certainty = S::Certainty;
type Text = S::Text;
type Timestamp = Set<members::timestamp>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct question(());
pub struct certainty(());
pub struct text(());
pub struct timestamp(());
}
}
pub struct AnswerBuilder<'a, S: answer_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<AnswerCertainty<'a>>,
::core::option::Option<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
::core::option::Option<jacquard_common::CowStr<'a>>,
::core::option::Option<jacquard_common::types::string::Datetime>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Answer<'a> {
pub fn new() -> AnswerBuilder<'a, answer_state::Empty> {
AnswerBuilder::new()
}
}
impl<'a> AnswerBuilder<'a, answer_state::Empty> {
pub fn new() -> Self {
AnswerBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> AnswerBuilder<'a, S>
where
S: answer_state::State,
S::Certainty: answer_state::IsUnset,
{
pub fn certainty(
mut self,
value: impl Into<AnswerCertainty<'a>>,
) -> AnswerBuilder<'a, answer_state::SetCertainty<S>> {
self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
AnswerBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> AnswerBuilder<'a, S>
where
S: answer_state::State,
S::Question: answer_state::IsUnset,
{
pub fn question(
mut self,
value: impl Into<crate::com_atproto::repo::strong_ref::StrongRef<'a>>,
) -> AnswerBuilder<'a, answer_state::SetQuestion<S>> {
self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
AnswerBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> AnswerBuilder<'a, S>
where
S: answer_state::State,
S::Text: answer_state::IsUnset,
{
pub fn text(
mut self,
value: impl Into<jacquard_common::CowStr<'a>>,
) -> AnswerBuilder<'a, answer_state::SetText<S>> {
self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
AnswerBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> AnswerBuilder<'a, S>
where
S: answer_state::State,
S::Timestamp: answer_state::IsUnset,
{
pub fn timestamp(
mut self,
value: impl Into<jacquard_common::types::string::Datetime>,
) -> AnswerBuilder<'a, answer_state::SetTimestamp<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
AnswerBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> AnswerBuilder<'a, S>
where
S: answer_state::State,
S::Question: answer_state::IsSet,
S::Certainty: answer_state::IsSet,
S::Text: answer_state::IsSet,
S::Timestamp: answer_state::IsSet,
{
pub fn build(self) -> Answer<'a> {
Answer {
certainty: self.__unsafe_private_named.0.unwrap(),
question: self.__unsafe_private_named.1.unwrap(),
text: self.__unsafe_private_named.2.unwrap(),
timestamp: self.__unsafe_private_named.3.unwrap(),
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>,
>,
) -> Answer<'a> {
Answer {
certainty: self.__unsafe_private_named.0.unwrap(),
question: self.__unsafe_private_named.1.unwrap(),
text: self.__unsafe_private_named.2.unwrap(),
timestamp: self.__unsafe_private_named.3.unwrap(),
extra_data: Some(extra_data),
}
}
}
impl<'a> Answer<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, AnswerRecord>,
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 AnswerCertainty<'a> {
DeadCertain,
FairlySure,
EducatedGuess,
WildGuess,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> AnswerCertainty<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::DeadCertain => "deadCertain",
Self::FairlySure => "fairlySure",
Self::EducatedGuess => "educatedGuess",
Self::WildGuess => "wildGuess",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for AnswerCertainty<'a> {
fn from(s: &'a str) -> Self {
match s {
"deadCertain" => Self::DeadCertain,
"fairlySure" => Self::FairlySure,
"educatedGuess" => Self::EducatedGuess,
"wildGuess" => Self::WildGuess,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for AnswerCertainty<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"deadCertain" => Self::DeadCertain,
"fairlySure" => Self::FairlySure,
"educatedGuess" => Self::EducatedGuess,
"wildGuess" => Self::WildGuess,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for AnswerCertainty<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for AnswerCertainty<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for AnswerCertainty<'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 AnswerCertainty<'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 AnswerCertainty<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for AnswerCertainty<'_> {
type Output = AnswerCertainty<'static>;
fn into_static(self) -> Self::Output {
match self {
AnswerCertainty::DeadCertain => AnswerCertainty::DeadCertain,
AnswerCertainty::FairlySure => AnswerCertainty::FairlySure,
AnswerCertainty::EducatedGuess => AnswerCertainty::EducatedGuess,
AnswerCertainty::WildGuess => AnswerCertainty::WildGuess,
AnswerCertainty::Other(v) => AnswerCertainty::Other(v.into_static()),
}
}
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct AnswerGetRecordOutput<'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: Answer<'a>,
}
impl From<AnswerGetRecordOutput<'_>> for Answer<'_> {
fn from(output: AnswerGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Answer<'_> {
const NSID: &'static str = "pub.quizzy.answer";
type Record = AnswerRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct AnswerRecord;
impl jacquard_common::xrpc::XrpcResp for AnswerRecord {
const NSID: &'static str = "pub.quizzy.answer";
const ENCODING: &'static str = "application/json";
type Output<'de> = AnswerGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for AnswerRecord {
const NSID: &'static str = "pub.quizzy.answer";
type Record = AnswerRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Answer<'a> {
fn nsid() -> &'static str {
"pub.quizzy.answer"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_pub_quizzy_answer()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
{
let value = &self.text;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 1000usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxLength {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"text",
),
max: 1000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.text;
{
let count = jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation::graphemes(
value.as_ref(),
true,
)
.count();
if count > 100usize {
return Err(::jacquard_lexicon::validation::ConstraintError::MaxGraphemes {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"text",
),
max: 100usize,
actual: count,
});
}
}
}
Ok(())
}
}
fn lexicon_doc_pub_quizzy_answer() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("pub.quizzy.answer"),
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(
"A person's answer to a question",
),
),
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("question"),
::jacquard_common::deps::smol_str::SmolStr::new_static("text"),
::jacquard_common::deps::smol_str::SmolStr::new_static("certainty"),
::jacquard_common::deps::smol_str::SmolStr::new_static("timestamp")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"certainty",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"How certain the person is about this answer",
),
),
format: None,
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(
"question",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Ref(::jacquard_lexicon::lexicon::LexRef {
description: None,
r#ref: ::jacquard_common::CowStr::new_static(
"com.atproto.repo.strongRef",
),
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"text",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static("The answer text"),
),
format: None,
default: None,
min_length: None,
max_length: Some(1000usize),
min_graphemes: None,
max_graphemes: Some(100usize),
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"timestamp",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"When this answer was submitted",
),
),
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
},
}),
}),
);
map
},
}
}