#[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::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::blog_pckt::mark::link;
#[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 LinkAttrs<S: BosStr = DefaultStr> {
pub href: UriValue<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rel: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub target: Option<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>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Link<S: BosStr = DefaultStr> {
pub attrs: link::LinkAttrs<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> LexiconSchema for LinkAttrs<S> {
fn nsid() -> &'static str {
"blog.pckt.mark.link"
}
fn def_name() -> &'static str {
"linkAttrs"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blog_pckt_mark_link()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.href;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 2000usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("href"),
max: 2000usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.rel {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("rel"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.target {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("target"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.title {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 500usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("title"),
max: 500usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for Link<S> {
fn nsid() -> &'static str {
"blog.pckt.mark.link"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blog_pckt_mark_link()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod link_attrs_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 Href;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Href = Unset;
}
pub struct SetHref<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetHref<St> {}
impl<St: State> State for SetHref<St> {
type Href = Set<members::href>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct href(());
}
}
pub struct LinkAttrsBuilder<S: BosStr, St: link_attrs_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<UriValue<S>>, Option<S>, Option<S>, Option<S>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> LinkAttrs<S> {
pub fn new() -> LinkAttrsBuilder<S, link_attrs_state::Empty> {
LinkAttrsBuilder::new()
}
}
impl<S: BosStr> LinkAttrsBuilder<S, link_attrs_state::Empty> {
pub fn new() -> Self {
LinkAttrsBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkAttrsBuilder<S, St>
where
St: link_attrs_state::State,
St::Href: link_attrs_state::IsUnset,
{
pub fn href(
mut self,
value: impl Into<UriValue<S>>,
) -> LinkAttrsBuilder<S, link_attrs_state::SetHref<St>> {
self._fields.0 = Option::Some(value.into());
LinkAttrsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: link_attrs_state::State> LinkAttrsBuilder<S, St> {
pub fn rel(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_rel(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: link_attrs_state::State> LinkAttrsBuilder<S, St> {
pub fn target(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_target(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: link_attrs_state::State> LinkAttrsBuilder<S, St> {
pub fn title(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_title(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> LinkAttrsBuilder<S, St>
where
St: link_attrs_state::State,
St::Href: link_attrs_state::IsSet,
{
pub fn build(self) -> LinkAttrs<S> {
LinkAttrs {
href: self._fields.0.unwrap(),
rel: self._fields.1,
target: self._fields.2,
title: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> LinkAttrs<S> {
LinkAttrs {
href: self._fields.0.unwrap(),
rel: self._fields.1,
target: self._fields.2,
title: self._fields.3,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_blog_pckt_mark_link() -> 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("blog.pckt.mark.link"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("linkAttrs"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static("Link attributes")),
required: Some(vec![SmolStr::new_static("href")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("href"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("The URL destination of the hyperlink"),
),
format: Some(LexStringFormat::Uri),
max_length: Some(2000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rel"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Defines the relationship between the current document and the linked resource (e.g., nofollow, noopener)",
),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("target"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Specifies where to open the linked document (e.g., _blank, _self)",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("title"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Additional information about the link, typically shown as a tooltip on hover",
),
),
max_length: Some(500usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Object(LexObject {
required: Some(vec![SmolStr::new_static("attrs")]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attrs"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#linkAttrs"),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod link_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 Attrs;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Attrs = Unset;
}
pub struct SetAttrs<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAttrs<St> {}
impl<St: State> State for SetAttrs<St> {
type Attrs = Set<members::attrs>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct attrs(());
}
}
pub struct LinkBuilder<S: BosStr, St: link_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<link::LinkAttrs<S>>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Link<S> {
pub fn new() -> LinkBuilder<S, link_state::Empty> {
LinkBuilder::new()
}
}
impl<S: BosStr> LinkBuilder<S, link_state::Empty> {
pub fn new() -> Self {
LinkBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkBuilder<S, St>
where
St: link_state::State,
St::Attrs: link_state::IsUnset,
{
pub fn attrs(
mut self,
value: impl Into<link::LinkAttrs<S>>,
) -> LinkBuilder<S, link_state::SetAttrs<St>> {
self._fields.0 = Option::Some(value.into());
LinkBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> LinkBuilder<S, St>
where
St: link_state::State,
St::Attrs: link_state::IsSet,
{
pub fn build(self) -> Link<S> {
Link {
attrs: self._fields.0.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Link<S> {
Link {
attrs: self._fields.0.unwrap(),
extra_data: Some(extra_data),
}
}
}