#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Link<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub children: std::option::Option<jacquard_common::types::value::Data<'a>>,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub decoration: std::option::Option<LinkDecoration<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::UriValue<'a>,
}
pub mod link_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 Uri;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Uri = Unset;
}
pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUri<S> {}
impl<S: State> State for SetUri<S> {
type Uri = Set<members::uri>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct uri(());
}
}
pub struct LinkBuilder<'a, S: link_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::types::value::Data<'a>>,
::core::option::Option<LinkDecoration<'a>>,
::core::option::Option<jacquard_common::types::string::UriValue<'a>>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Link<'a> {
pub fn new() -> LinkBuilder<'a, link_state::Empty> {
LinkBuilder::new()
}
}
impl<'a> LinkBuilder<'a, link_state::Empty> {
pub fn new() -> Self {
LinkBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: link_state::State> LinkBuilder<'a, S> {
pub fn children(
mut self,
value: impl Into<Option<jacquard_common::types::value::Data<'a>>>,
) -> Self {
self.__unsafe_private_named.0 = value.into();
self
}
pub fn maybe_children(
mut self,
value: Option<jacquard_common::types::value::Data<'a>>,
) -> Self {
self.__unsafe_private_named.0 = value;
self
}
}
impl<'a, S: link_state::State> LinkBuilder<'a, S> {
pub fn decoration(mut self, value: impl Into<Option<LinkDecoration<'a>>>) -> Self {
self.__unsafe_private_named.1 = value.into();
self
}
pub fn maybe_decoration(mut self, value: Option<LinkDecoration<'a>>) -> Self {
self.__unsafe_private_named.1 = value;
self
}
}
impl<'a, S> LinkBuilder<'a, S>
where
S: link_state::State,
S::Uri: link_state::IsUnset,
{
pub fn uri(
mut self,
value: impl Into<jacquard_common::types::string::UriValue<'a>>,
) -> LinkBuilder<'a, link_state::SetUri<S>> {
self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
LinkBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> LinkBuilder<'a, S>
where
S: link_state::State,
S::Uri: link_state::IsSet,
{
pub fn build(self) -> Link<'a> {
Link {
children: self.__unsafe_private_named.0,
decoration: self.__unsafe_private_named.1,
uri: self.__unsafe_private_named.2.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>,
>,
) -> Link<'a> {
Link {
children: self.__unsafe_private_named.0,
decoration: self.__unsafe_private_named.1,
uri: self.__unsafe_private_named.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum LinkDecoration<'a> {
None,
Underline,
Other(jacquard_common::CowStr<'a>),
}
impl<'a> LinkDecoration<'a> {
pub fn as_str(&self) -> &str {
match self {
Self::None => "none",
Self::Underline => "underline",
Self::Other(s) => s.as_ref(),
}
}
}
impl<'a> From<&'a str> for LinkDecoration<'a> {
fn from(s: &'a str) -> Self {
match s {
"none" => Self::None,
"underline" => Self::Underline,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> From<String> for LinkDecoration<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"none" => Self::None,
"underline" => Self::Underline,
_ => Self::Other(jacquard_common::CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for LinkDecoration<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for LinkDecoration<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for LinkDecoration<'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 LinkDecoration<'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 LinkDecoration<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for LinkDecoration<'_> {
type Output = LinkDecoration<'static>;
fn into_static(self) -> Self::Output {
match self {
LinkDecoration::None => LinkDecoration::None,
LinkDecoration::Underline => LinkDecoration::Underline,
LinkDecoration::Other(v) => LinkDecoration::Other(v.into_static()),
}
}
}
#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct LinkOutput<'a> {
#[serde(flatten)]
#[serde(borrow)]
pub value: crate::at_inlay::Response<'a>,
}
pub struct LinkResponse;
impl jacquard_common::xrpc::XrpcResp for LinkResponse {
const NSID: &'static str = "org.atsui.Link";
const ENCODING: &'static str = "application/json";
type Output<'de> = LinkOutput<'de>;
type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for Link<'a> {
const NSID: &'static str = "org.atsui.Link";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = LinkResponse;
}
pub struct LinkRequest;
impl jacquard_common::xrpc::XrpcEndpoint for LinkRequest {
const PATH: &'static str = "/xrpc/org.atsui.Link";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = Link<'de>;
type Response = LinkResponse;
}