// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.anisota.lab.inkblot
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.
//! Generated bindings for the `net.anisota.lab.inkblot` Lexicon namespace/module.
pub mod perception;
#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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};
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::{Deserialize, Serialize};
/// A symmetric Rorschach-style inkblot crafted in the Anisota Lab's Social Inkblot Test and saved to the owner's library. The blot is fully reproducible from its integer 'seed' and its generation 'params'; 'palette' names the ink colour. A rendered PNG data URL is stored in 'image' so the blot can be shown anywhere (including by other people viewing the social gallery) without re-running the generator. Inkblots carry no user-supplied name: the record's TID rkey is its identifier and display name everywhere it is shown.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "net.anisota.lab.inkblot",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Inkblot<S: BosStr = DefaultStr> {
///When the inkblot was saved
pub created_at: Datetime,
///A rendered PNG of the blot as a data URL, for display
#[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<S>,
///Ink palette id (classic, sepia, indigo, blood, moss)
pub palette: S,
///The generation parameters (complexity, blobiness, spread, spatter, radial)
#[serde(skip_serializing_if = "Option::is_none")]
pub params: Option<Data<S>>,
///The deterministic RNG seed that reproduces the blot
pub seed: i64,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
/// Typed wrapper for GetRecord response with this collection's record type.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct InkblotGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Inkblot<S>,
}
impl<S: BosStr> Inkblot<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, InkblotRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
/// Marker type for deserializing records from this collection.
#[derive(Debug, Serialize, Deserialize)]
pub struct InkblotRecord;
impl XrpcResp for InkblotRecord {
const NSID: &'static str = "net.anisota.lab.inkblot";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = InkblotGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<InkblotGetRecordOutput<S>> for Inkblot<S> {
fn from(output: InkblotGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Inkblot<S> {
const NSID: &'static str = "net.anisota.lab.inkblot";
type Record = InkblotRecord;
}
impl Collection for InkblotRecord {
const NSID: &'static str = "net.anisota.lab.inkblot";
type Record = InkblotRecord;
}
impl<S: BosStr> LexiconSchema for Inkblot<S> {
fn nsid() -> &'static str {
"net.anisota.lab.inkblot"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_inkblot()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.image {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("image"),
max: 200000usize,
actual: <str>::len(value.as_ref()),
});
}
}
{
let value = &self.palette;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 64usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("palette"),
max: 64usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod inkblot_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
/// State trait tracking which required fields have been set
pub trait State: sealed::Sealed {
type CreatedAt;
type Palette;
type Seed;
}
/// Empty state - all required fields are unset
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Palette = Unset;
type Seed = Unset;
}
///State transition - sets the `created_at` field to Set
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type CreatedAt = Set<members::created_at>;
type Palette = St::Palette;
type Seed = St::Seed;
}
///State transition - sets the `palette` field to Set
pub struct SetPalette<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPalette<St> {}
impl<St: State> State for SetPalette<St> {
type CreatedAt = St::CreatedAt;
type Palette = Set<members::palette>;
type Seed = St::Seed;
}
///State transition - sets the `seed` field to Set
pub struct SetSeed<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSeed<St> {}
impl<St: State> State for SetSeed<St> {
type CreatedAt = St::CreatedAt;
type Palette = St::Palette;
type Seed = Set<members::seed>;
}
/// Marker types for field names
#[allow(non_camel_case_types)]
pub mod members {
///Marker type for the `created_at` field
pub struct created_at(());
///Marker type for the `palette` field
pub struct palette(());
///Marker type for the `seed` field
pub struct seed(());
}
}
/// Builder for constructing an instance of this type.
pub struct InkblotBuilder<St: inkblot_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<S>,
Option<Data<S>>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl Inkblot<DefaultStr> {
/// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
pub fn new() -> InkblotBuilder<inkblot_state::Empty, DefaultStr> {
InkblotBuilder::new()
}
}
impl<S: BosStr> Inkblot<S> {
/// Create a new builder for this type
pub fn builder() -> InkblotBuilder<inkblot_state::Empty, S> {
InkblotBuilder::builder()
}
}
impl InkblotBuilder<inkblot_state::Empty, DefaultStr> {
/// Create a new builder with all fields unset, using the default string type, if needed
pub fn new() -> Self {
InkblotBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> InkblotBuilder<inkblot_state::Empty, S> {
/// Create a new builder with all fields unset
pub fn builder() -> Self {
InkblotBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> InkblotBuilder<St, S>
where
St: inkblot_state::State,
St::CreatedAt: inkblot_state::IsUnset,
{
/// Set the `createdAt` field (required)
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> InkblotBuilder<inkblot_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
InkblotBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: inkblot_state::State, S: BosStr> InkblotBuilder<St, S> {
/// Set the `image` field (optional)
pub fn image(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
/// Set the `image` field to an Option value (optional)
pub fn maybe_image(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<St, S: BosStr> InkblotBuilder<St, S>
where
St: inkblot_state::State,
St::Palette: inkblot_state::IsUnset,
{
/// Set the `palette` field (required)
pub fn palette(
mut self,
value: impl Into<S>,
) -> InkblotBuilder<inkblot_state::SetPalette<St>, S> {
self._fields.2 = Option::Some(value.into());
InkblotBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: inkblot_state::State, S: BosStr> InkblotBuilder<St, S> {
/// Set the `params` field (optional)
pub fn params(mut self, value: impl Into<Option<Data<S>>>) -> Self {
self._fields.3 = value.into();
self
}
/// Set the `params` field to an Option value (optional)
pub fn maybe_params(mut self, value: Option<Data<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<St, S: BosStr> InkblotBuilder<St, S>
where
St: inkblot_state::State,
St::Seed: inkblot_state::IsUnset,
{
/// Set the `seed` field (required)
pub fn seed(mut self, value: impl Into<i64>) -> InkblotBuilder<inkblot_state::SetSeed<St>, S> {
self._fields.4 = Option::Some(value.into());
InkblotBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> InkblotBuilder<St, S>
where
St: inkblot_state::State,
St::CreatedAt: inkblot_state::IsSet,
St::Palette: inkblot_state::IsSet,
St::Seed: inkblot_state::IsSet,
{
/// Build the final struct.
pub fn build(self) -> Inkblot<S> {
Inkblot {
created_at: self._fields.0.unwrap(),
image: self._fields.1,
palette: self._fields.2.unwrap(),
params: self._fields.3,
seed: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
/// Build the final struct with custom extra_data.
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Inkblot<S> {
Inkblot {
created_at: self._fields.0.unwrap(),
image: self._fields.1,
palette: self._fields.2.unwrap(),
params: self._fields.3,
seed: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_inkblot() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("net.anisota.lab.inkblot"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A symmetric Rorschach-style inkblot crafted in the Anisota Lab's Social Inkblot Test and saved to the owner's library. The blot is fully reproducible from its integer 'seed' and its generation 'params'; 'palette' names the ink colour. A rendered PNG data URL is stored in 'image' so the blot can be shown anywhere (including by other people viewing the social gallery) without re-running the generator. Inkblots carry no user-supplied name: the record's TID rkey is its identifier and display name everywhere it is shown.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("seed"), SmolStr::new_static("palette"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the inkblot was saved"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("image"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"A rendered PNG of the blot as a data URL, for display",
),
),
max_length: Some(200000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("palette"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Ink palette id (classic, sepia, indigo, blood, moss)",
),
),
max_length: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("params"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("seed"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}