// @generated by jacquard-lexicon. DO NOT EDIT. // // Lexicon: org.atsui.Link // // This file was automatically generated from Lexicon schemas. // Any manual changes will be overwritten on the next regeneration. #[allow(unused_imports)] use alloc::collections::BTreeMap; #[allow(unused_imports)] use core::marker::PhantomData; use jacquard_common::CowStr; use jacquard_common::types::string::UriValue; use jacquard_common::types::value::Data; use jacquard_derive::{IntoStatic, lexicon}; use serde::{Serialize, Deserialize}; use crate::at_inlay::Response; #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct Link<'a> { #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub children: Option>, #[serde(skip_serializing_if = "Option::is_none")] #[serde(borrow)] pub decoration: Option>, #[serde(borrow)] pub uri: UriValue<'a>, } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum LinkDecoration<'a> { None, Underline, Other(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(CowStr::from(s)), } } } impl<'a> From for LinkDecoration<'a> { fn from(s: String) -> Self { match s.as_str() { "none" => Self::None, "underline" => Self::Underline, _ => Self::Other(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 for LinkDecoration<'a> { fn as_ref(&self) -> &str { self.as_str() } } impl<'a> serde::Serialize for LinkDecoration<'a> { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, { serializer.serialize_str(self.as_str()) } } impl<'de, 'a> serde::Deserialize<'de> for LinkDecoration<'a> where 'de: 'a, { fn deserialize(deserializer: D) -> Result 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()), } } } #[lexicon] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)] #[serde(rename_all = "camelCase")] pub struct LinkOutput<'a> { #[serde(flatten)] #[serde(borrow)] pub value: Response<'a>, } /// Response type for org.atsui.Link 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; } /// Endpoint type for org.atsui.Link 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; } pub mod link_state { pub use crate::builder_types::{Set, Unset, IsSet, IsUnset}; #[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 Uri; } /// Empty state - all required fields are unset pub struct Empty(()); impl sealed::Sealed for Empty {} impl State for Empty { type Uri = Unset; } ///State transition - sets the `uri` field to Set pub struct SetUri(PhantomData S>); impl sealed::Sealed for SetUri {} impl State for SetUri { type Uri = Set; } /// Marker types for field names #[allow(non_camel_case_types)] pub mod members { ///Marker type for the `uri` field pub struct uri(()); } } /// Builder for constructing an instance of this type pub struct LinkBuilder<'a, S: link_state::State> { _state: PhantomData S>, _fields: (Option>, Option>, Option>), _lifetime: PhantomData<&'a ()>, } impl<'a> Link<'a> { /// Create a new builder for this type pub fn new() -> LinkBuilder<'a, link_state::Empty> { LinkBuilder::new() } } impl<'a> LinkBuilder<'a, link_state::Empty> { /// Create a new builder with all fields unset pub fn new() -> Self { LinkBuilder { _state: PhantomData, _fields: (None, None, None), _lifetime: PhantomData, } } } impl<'a, S: link_state::State> LinkBuilder<'a, S> { /// Set the `children` field (optional) pub fn children(mut self, value: impl Into>>) -> Self { self._fields.0 = value.into(); self } /// Set the `children` field to an Option value (optional) pub fn maybe_children(mut self, value: Option>) -> Self { self._fields.0 = value; self } } impl<'a, S: link_state::State> LinkBuilder<'a, S> { /// Set the `decoration` field (optional) pub fn decoration(mut self, value: impl Into>>) -> Self { self._fields.1 = value.into(); self } /// Set the `decoration` field to an Option value (optional) pub fn maybe_decoration(mut self, value: Option>) -> Self { self._fields.1 = value; self } } impl<'a, S> LinkBuilder<'a, S> where S: link_state::State, S::Uri: link_state::IsUnset, { /// Set the `uri` field (required) pub fn uri( mut self, value: impl Into>, ) -> LinkBuilder<'a, link_state::SetUri> { self._fields.2 = Option::Some(value.into()); LinkBuilder { _state: PhantomData, _fields: self._fields, _lifetime: PhantomData, } } } impl<'a, S> LinkBuilder<'a, S> where S: link_state::State, S::Uri: link_state::IsSet, { /// Build the final struct pub fn build(self) -> Link<'a> { Link { children: self._fields.0, decoration: self._fields.1, uri: self._fields.2.unwrap(), extra_data: Default::default(), } } /// Build the final struct with custom extra_data pub fn build_with_data( self, extra_data: BTreeMap>, ) -> Link<'a> { Link { children: self._fields.0, decoration: self._fields.1, uri: self._fields.2.unwrap(), extra_data: Some(extra_data), } } }