#[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::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::pub_leaflet::blocks::blockquote::Blockquote;
use crate::pub_leaflet::blocks::bsky_post::BskyPost;
use crate::pub_leaflet::blocks::button::Button;
use crate::pub_leaflet::blocks::code::Code;
use crate::pub_leaflet::blocks::header::Header;
use crate::pub_leaflet::blocks::horizontal_rule::HorizontalRule;
use crate::pub_leaflet::blocks::iframe::Iframe;
use crate::pub_leaflet::blocks::image::Image;
use crate::pub_leaflet::blocks::math::Math;
use crate::pub_leaflet::blocks::ordered_list::OrderedList;
use crate::pub_leaflet::blocks::page::Page;
use crate::pub_leaflet::blocks::poll::Poll;
use crate::pub_leaflet::blocks::text::Text;
use crate::pub_leaflet::blocks::unordered_list::UnorderedList;
use crate::pub_leaflet::blocks::website::Website;
use crate::pub_leaflet::pages::canvas;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Block<S: BosStr = DefaultStr> {
pub block: BlockBlock<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub height: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rotation: Option<i64>,
pub width: i64,
pub x: i64,
pub y: i64,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum BlockBlock<S: BosStr = DefaultStr> {
#[serde(rename = "pub.leaflet.blocks.iframe")]
Iframe(Box<Iframe<S>>),
#[serde(rename = "pub.leaflet.blocks.text")]
Text(Box<Text<S>>),
#[serde(rename = "pub.leaflet.blocks.blockquote")]
Blockquote(Box<Blockquote<S>>),
#[serde(rename = "pub.leaflet.blocks.header")]
Header(Box<Header<S>>),
#[serde(rename = "pub.leaflet.blocks.image")]
Image(Box<Image<S>>),
#[serde(rename = "pub.leaflet.blocks.unorderedList")]
UnorderedList(Box<UnorderedList<S>>),
#[serde(rename = "pub.leaflet.blocks.orderedList")]
OrderedList(Box<OrderedList<S>>),
#[serde(rename = "pub.leaflet.blocks.website")]
Website(Box<Website<S>>),
#[serde(rename = "pub.leaflet.blocks.math")]
Math(Box<Math<S>>),
#[serde(rename = "pub.leaflet.blocks.code")]
Code(Box<Code<S>>),
#[serde(rename = "pub.leaflet.blocks.horizontalRule")]
HorizontalRule(Box<HorizontalRule<S>>),
#[serde(rename = "pub.leaflet.blocks.bskyPost")]
BskyPost(Box<BskyPost<S>>),
#[serde(rename = "pub.leaflet.blocks.page")]
Page(Box<Page<S>>),
#[serde(rename = "pub.leaflet.blocks.poll")]
Poll(Box<Poll<S>>),
#[serde(rename = "pub.leaflet.blocks.button")]
Button(Box<Button<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Canvas<S: BosStr = DefaultStr> {
pub blocks: Vec<canvas::Block<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<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 Position<S: BosStr = DefaultStr> {
pub block: Vec<i64>,
pub offset: i64,
#[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 Quote<S: BosStr = DefaultStr> {
pub end: canvas::Position<S>,
pub start: canvas::Position<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, Hash)]
pub struct TextAlignCenter;
impl core::fmt::Display for TextAlignCenter {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "textAlignCenter")
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct TextAlignLeft;
impl core::fmt::Display for TextAlignLeft {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "textAlignLeft")
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct TextAlignRight;
impl core::fmt::Display for TextAlignRight {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "textAlignRight")
}
}
impl<S: BosStr> LexiconSchema for Block<S> {
fn nsid() -> &'static str {
"pub.leaflet.pages.canvas"
}
fn def_name() -> &'static str {
"block"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_pages_canvas()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Canvas<S> {
fn nsid() -> &'static str {
"pub.leaflet.pages.canvas"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_pages_canvas()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Position<S> {
fn nsid() -> &'static str {
"pub.leaflet.pages.canvas"
}
fn def_name() -> &'static str {
"position"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_pages_canvas()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Quote<S> {
fn nsid() -> &'static str {
"pub.leaflet.pages.canvas"
}
fn def_name() -> &'static str {
"quote"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_pub_leaflet_pages_canvas()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod block_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Width;
type X;
type Block;
type Y;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Width = Unset;
type X = Unset;
type Block = Unset;
type Y = Unset;
}
pub struct SetWidth<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetWidth<St> {}
impl<St: State> State for SetWidth<St> {
type Width = Set<members::width>;
type X = St::X;
type Block = St::Block;
type Y = St::Y;
}
pub struct SetX<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetX<St> {}
impl<St: State> State for SetX<St> {
type Width = St::Width;
type X = Set<members::x>;
type Block = St::Block;
type Y = St::Y;
}
pub struct SetBlock<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBlock<St> {}
impl<St: State> State for SetBlock<St> {
type Width = St::Width;
type X = St::X;
type Block = Set<members::block>;
type Y = St::Y;
}
pub struct SetY<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetY<St> {}
impl<St: State> State for SetY<St> {
type Width = St::Width;
type X = St::X;
type Block = St::Block;
type Y = Set<members::y>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct width(());
pub struct x(());
pub struct block(());
pub struct y(());
}
}
pub struct BlockBuilder<S: BosStr, St: block_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<BlockBlock<S>>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<i64>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Block<S> {
pub fn new() -> BlockBuilder<S, block_state::Empty> {
BlockBuilder::new()
}
}
impl<S: BosStr> BlockBuilder<S, block_state::Empty> {
pub fn new() -> Self {
BlockBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BlockBuilder<S, St>
where
St: block_state::State,
St::Block: block_state::IsUnset,
{
pub fn block(
mut self,
value: impl Into<BlockBlock<S>>,
) -> BlockBuilder<S, block_state::SetBlock<St>> {
self._fields.0 = Option::Some(value.into());
BlockBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: block_state::State> BlockBuilder<S, St> {
pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_height(mut self, value: Option<i64>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: block_state::State> BlockBuilder<S, St> {
pub fn rotation(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_rotation(mut self, value: Option<i64>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> BlockBuilder<S, St>
where
St: block_state::State,
St::Width: block_state::IsUnset,
{
pub fn width(mut self, value: impl Into<i64>) -> BlockBuilder<S, block_state::SetWidth<St>> {
self._fields.3 = Option::Some(value.into());
BlockBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BlockBuilder<S, St>
where
St: block_state::State,
St::X: block_state::IsUnset,
{
pub fn x(mut self, value: impl Into<i64>) -> BlockBuilder<S, block_state::SetX<St>> {
self._fields.4 = Option::Some(value.into());
BlockBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BlockBuilder<S, St>
where
St: block_state::State,
St::Y: block_state::IsUnset,
{
pub fn y(mut self, value: impl Into<i64>) -> BlockBuilder<S, block_state::SetY<St>> {
self._fields.5 = Option::Some(value.into());
BlockBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BlockBuilder<S, St>
where
St: block_state::State,
St::Width: block_state::IsSet,
St::X: block_state::IsSet,
St::Block: block_state::IsSet,
St::Y: block_state::IsSet,
{
pub fn build(self) -> Block<S> {
Block {
block: self._fields.0.unwrap(),
height: self._fields.1,
rotation: self._fields.2,
width: self._fields.3.unwrap(),
x: self._fields.4.unwrap(),
y: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Block<S> {
Block {
block: self._fields.0.unwrap(),
height: self._fields.1,
rotation: self._fields.2,
width: self._fields.3.unwrap(),
x: self._fields.4.unwrap(),
y: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_pub_leaflet_pages_canvas() -> 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("pub.leaflet.pages.canvas"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("block"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("block"),
SmolStr::new_static("x"),
SmolStr::new_static("y"),
SmolStr::new_static("width"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("block"),
LexObjectProperty::Union(LexRefUnion {
refs: vec![
CowStr::new_static("pub.leaflet.blocks.iframe"),
CowStr::new_static("pub.leaflet.blocks.text"),
CowStr::new_static("pub.leaflet.blocks.blockquote"),
CowStr::new_static("pub.leaflet.blocks.header"),
CowStr::new_static("pub.leaflet.blocks.image"),
CowStr::new_static("pub.leaflet.blocks.unorderedList"),
CowStr::new_static("pub.leaflet.blocks.orderedList"),
CowStr::new_static("pub.leaflet.blocks.website"),
CowStr::new_static("pub.leaflet.blocks.math"),
CowStr::new_static("pub.leaflet.blocks.code"),
CowStr::new_static("pub.leaflet.blocks.horizontalRule"),
CowStr::new_static("pub.leaflet.blocks.bskyPost"),
CowStr::new_static("pub.leaflet.blocks.page"),
CowStr::new_static("pub.leaflet.blocks.poll"),
CowStr::new_static("pub.leaflet.blocks.button"),
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("height"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rotation"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("width"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("x"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("y"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("blocks")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("blocks"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Ref(LexRef {
r#ref: CowStr::new_static("#block"),
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("id"),
LexObjectProperty::String(LexString {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("position"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("block"),
SmolStr::new_static("offset"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("block"),
LexObjectProperty::Array(LexArray {
items: LexArrayItem::Integer(LexInteger {
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("offset"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("quote"),
LexUserType::Object(LexObject {
required: Some(vec![
SmolStr::new_static("start"),
SmolStr::new_static("end"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("end"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#position"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("start"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#position"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("textAlignCenter"),
LexUserType::Token(LexToken {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("textAlignLeft"),
LexUserType::Token(LexToken {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("textAlignRight"),
LexUserType::Token(LexToken {
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod canvas_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Blocks;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Blocks = Unset;
}
pub struct SetBlocks<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBlocks<St> {}
impl<St: State> State for SetBlocks<St> {
type Blocks = Set<members::blocks>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct blocks(());
}
}
pub struct CanvasBuilder<S: BosStr, St: canvas_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<canvas::Block<S>>>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Canvas<S> {
pub fn new() -> CanvasBuilder<S, canvas_state::Empty> {
CanvasBuilder::new()
}
}
impl<S: BosStr> CanvasBuilder<S, canvas_state::Empty> {
pub fn new() -> Self {
CanvasBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CanvasBuilder<S, St>
where
St: canvas_state::State,
St::Blocks: canvas_state::IsUnset,
{
pub fn blocks(
mut self,
value: impl Into<Vec<canvas::Block<S>>>,
) -> CanvasBuilder<S, canvas_state::SetBlocks<St>> {
self._fields.0 = Option::Some(value.into());
CanvasBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: canvas_state::State> CanvasBuilder<S, St> {
pub fn id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_id(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> CanvasBuilder<S, St>
where
St: canvas_state::State,
St::Blocks: canvas_state::IsSet,
{
pub fn build(self) -> Canvas<S> {
Canvas {
blocks: self._fields.0.unwrap(),
id: self._fields.1,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Canvas<S> {
Canvas {
blocks: self._fields.0.unwrap(),
id: self._fields.1,
extra_data: Some(extra_data),
}
}
}
pub mod position_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Block;
type Offset;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Block = Unset;
type Offset = Unset;
}
pub struct SetBlock<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBlock<St> {}
impl<St: State> State for SetBlock<St> {
type Block = Set<members::block>;
type Offset = St::Offset;
}
pub struct SetOffset<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOffset<St> {}
impl<St: State> State for SetOffset<St> {
type Block = St::Block;
type Offset = Set<members::offset>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct block(());
pub struct offset(());
}
}
pub struct PositionBuilder<S: BosStr, St: position_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Vec<i64>>, Option<i64>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Position<S> {
pub fn new() -> PositionBuilder<S, position_state::Empty> {
PositionBuilder::new()
}
}
impl<S: BosStr> PositionBuilder<S, position_state::Empty> {
pub fn new() -> Self {
PositionBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PositionBuilder<S, St>
where
St: position_state::State,
St::Block: position_state::IsUnset,
{
pub fn block(
mut self,
value: impl Into<Vec<i64>>,
) -> PositionBuilder<S, position_state::SetBlock<St>> {
self._fields.0 = Option::Some(value.into());
PositionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PositionBuilder<S, St>
where
St: position_state::State,
St::Offset: position_state::IsUnset,
{
pub fn offset(
mut self,
value: impl Into<i64>,
) -> PositionBuilder<S, position_state::SetOffset<St>> {
self._fields.1 = Option::Some(value.into());
PositionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> PositionBuilder<S, St>
where
St: position_state::State,
St::Block: position_state::IsSet,
St::Offset: position_state::IsSet,
{
pub fn build(self) -> Position<S> {
Position {
block: self._fields.0.unwrap(),
offset: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Position<S> {
Position {
block: self._fields.0.unwrap(),
offset: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}
pub mod quote_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type End;
type Start;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type End = Unset;
type Start = Unset;
}
pub struct SetEnd<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEnd<St> {}
impl<St: State> State for SetEnd<St> {
type End = Set<members::end>;
type Start = St::Start;
}
pub struct SetStart<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStart<St> {}
impl<St: State> State for SetStart<St> {
type End = St::End;
type Start = Set<members::start>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct end(());
pub struct start(());
}
}
pub struct QuoteBuilder<S: BosStr, St: quote_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<canvas::Position<S>>, Option<canvas::Position<S>>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Quote<S> {
pub fn new() -> QuoteBuilder<S, quote_state::Empty> {
QuoteBuilder::new()
}
}
impl<S: BosStr> QuoteBuilder<S, quote_state::Empty> {
pub fn new() -> Self {
QuoteBuilder {
_state: PhantomData,
_fields: (None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuoteBuilder<S, St>
where
St: quote_state::State,
St::End: quote_state::IsUnset,
{
pub fn end(
mut self,
value: impl Into<canvas::Position<S>>,
) -> QuoteBuilder<S, quote_state::SetEnd<St>> {
self._fields.0 = Option::Some(value.into());
QuoteBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuoteBuilder<S, St>
where
St: quote_state::State,
St::Start: quote_state::IsUnset,
{
pub fn start(
mut self,
value: impl Into<canvas::Position<S>>,
) -> QuoteBuilder<S, quote_state::SetStart<St>> {
self._fields.1 = Option::Some(value.into());
QuoteBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> QuoteBuilder<S, St>
where
St: quote_state::State,
St::End: quote_state::IsSet,
St::Start: quote_state::IsSet,
{
pub fn build(self) -> Quote<S> {
Quote {
end: self._fields.0.unwrap(),
start: self._fields.1.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Quote<S> {
Quote {
end: self._fields.0.unwrap(),
start: self._fields.1.unwrap(),
extra_data: Some(extra_data),
}
}
}