jacquard_api/tools_ozone/setting/
remove_options.rs1#[allow(unused_imports)]
9use alloc::collections::BTreeMap;
10
11#[allow(unused_imports)]
12use core::marker::PhantomData;
13use jacquard_common::CowStr;
14use jacquard_common::types::string::Nsid;
15use jacquard_derive::{IntoStatic, lexicon};
16use serde::{Serialize, Deserialize};
17
18#[lexicon]
19#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
20#[serde(rename_all = "camelCase")]
21pub struct RemoveOptions<'a> {
22 #[serde(borrow)]
23 pub keys: Vec<Nsid<'a>>,
24 #[serde(borrow)]
25 pub scope: RemoveOptionsScope<'a>,
26}
27
28
29#[derive(Debug, Clone, PartialEq, Eq, Hash)]
30pub enum RemoveOptionsScope<'a> {
31 Instance,
32 Personal,
33 Other(CowStr<'a>),
34}
35
36impl<'a> RemoveOptionsScope<'a> {
37 pub fn as_str(&self) -> &str {
38 match self {
39 Self::Instance => "instance",
40 Self::Personal => "personal",
41 Self::Other(s) => s.as_ref(),
42 }
43 }
44}
45
46impl<'a> From<&'a str> for RemoveOptionsScope<'a> {
47 fn from(s: &'a str) -> Self {
48 match s {
49 "instance" => Self::Instance,
50 "personal" => Self::Personal,
51 _ => Self::Other(CowStr::from(s)),
52 }
53 }
54}
55
56impl<'a> From<String> for RemoveOptionsScope<'a> {
57 fn from(s: String) -> Self {
58 match s.as_str() {
59 "instance" => Self::Instance,
60 "personal" => Self::Personal,
61 _ => Self::Other(CowStr::from(s)),
62 }
63 }
64}
65
66impl<'a> core::fmt::Display for RemoveOptionsScope<'a> {
67 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
68 write!(f, "{}", self.as_str())
69 }
70}
71
72impl<'a> AsRef<str> for RemoveOptionsScope<'a> {
73 fn as_ref(&self) -> &str {
74 self.as_str()
75 }
76}
77
78impl<'a> serde::Serialize for RemoveOptionsScope<'a> {
79 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
80 where
81 S: serde::Serializer,
82 {
83 serializer.serialize_str(self.as_str())
84 }
85}
86
87impl<'de, 'a> serde::Deserialize<'de> for RemoveOptionsScope<'a>
88where
89 'de: 'a,
90{
91 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
92 where
93 D: serde::Deserializer<'de>,
94 {
95 let s = <&'de str>::deserialize(deserializer)?;
96 Ok(Self::from(s))
97 }
98}
99
100impl<'a> Default for RemoveOptionsScope<'a> {
101 fn default() -> Self {
102 Self::Other(Default::default())
103 }
104}
105
106impl jacquard_common::IntoStatic for RemoveOptionsScope<'_> {
107 type Output = RemoveOptionsScope<'static>;
108 fn into_static(self) -> Self::Output {
109 match self {
110 RemoveOptionsScope::Instance => RemoveOptionsScope::Instance,
111 RemoveOptionsScope::Personal => RemoveOptionsScope::Personal,
112 RemoveOptionsScope::Other(v) => RemoveOptionsScope::Other(v.into_static()),
113 }
114 }
115}
116
117
118#[lexicon]
119#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
120#[serde(rename_all = "camelCase")]
121pub struct RemoveOptionsOutput<'a> {}
122pub struct RemoveOptionsResponse;
124impl jacquard_common::xrpc::XrpcResp for RemoveOptionsResponse {
125 const NSID: &'static str = "tools.ozone.setting.removeOptions";
126 const ENCODING: &'static str = "application/json";
127 type Output<'de> = RemoveOptionsOutput<'de>;
128 type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
129}
130
131impl<'a> jacquard_common::xrpc::XrpcRequest for RemoveOptions<'a> {
132 const NSID: &'static str = "tools.ozone.setting.removeOptions";
133 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
134 "application/json",
135 );
136 type Response = RemoveOptionsResponse;
137}
138
139pub struct RemoveOptionsRequest;
141impl jacquard_common::xrpc::XrpcEndpoint for RemoveOptionsRequest {
142 const PATH: &'static str = "/xrpc/tools.ozone.setting.removeOptions";
143 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
144 "application/json",
145 );
146 type Request<'de> = RemoveOptions<'de>;
147 type Response = RemoveOptionsResponse;
148}
149
150pub mod remove_options_state {
151
152 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
153 #[allow(unused)]
154 use ::core::marker::PhantomData;
155 mod sealed {
156 pub trait Sealed {}
157 }
158 pub trait State: sealed::Sealed {
160 type Keys;
161 type Scope;
162 }
163 pub struct Empty(());
165 impl sealed::Sealed for Empty {}
166 impl State for Empty {
167 type Keys = Unset;
168 type Scope = Unset;
169 }
170 pub struct SetKeys<S: State = Empty>(PhantomData<fn() -> S>);
172 impl<S: State> sealed::Sealed for SetKeys<S> {}
173 impl<S: State> State for SetKeys<S> {
174 type Keys = Set<members::keys>;
175 type Scope = S::Scope;
176 }
177 pub struct SetScope<S: State = Empty>(PhantomData<fn() -> S>);
179 impl<S: State> sealed::Sealed for SetScope<S> {}
180 impl<S: State> State for SetScope<S> {
181 type Keys = S::Keys;
182 type Scope = Set<members::scope>;
183 }
184 #[allow(non_camel_case_types)]
186 pub mod members {
187 pub struct keys(());
189 pub struct scope(());
191 }
192}
193
194pub struct RemoveOptionsBuilder<'a, S: remove_options_state::State> {
196 _state: PhantomData<fn() -> S>,
197 _fields: (Option<Vec<Nsid<'a>>>, Option<RemoveOptionsScope<'a>>),
198 _lifetime: PhantomData<&'a ()>,
199}
200
201impl<'a> RemoveOptions<'a> {
202 pub fn new() -> RemoveOptionsBuilder<'a, remove_options_state::Empty> {
204 RemoveOptionsBuilder::new()
205 }
206}
207
208impl<'a> RemoveOptionsBuilder<'a, remove_options_state::Empty> {
209 pub fn new() -> Self {
211 RemoveOptionsBuilder {
212 _state: PhantomData,
213 _fields: (None, None),
214 _lifetime: PhantomData,
215 }
216 }
217}
218
219impl<'a, S> RemoveOptionsBuilder<'a, S>
220where
221 S: remove_options_state::State,
222 S::Keys: remove_options_state::IsUnset,
223{
224 pub fn keys(
226 mut self,
227 value: impl Into<Vec<Nsid<'a>>>,
228 ) -> RemoveOptionsBuilder<'a, remove_options_state::SetKeys<S>> {
229 self._fields.0 = Option::Some(value.into());
230 RemoveOptionsBuilder {
231 _state: PhantomData,
232 _fields: self._fields,
233 _lifetime: PhantomData,
234 }
235 }
236}
237
238impl<'a, S> RemoveOptionsBuilder<'a, S>
239where
240 S: remove_options_state::State,
241 S::Scope: remove_options_state::IsUnset,
242{
243 pub fn scope(
245 mut self,
246 value: impl Into<RemoveOptionsScope<'a>>,
247 ) -> RemoveOptionsBuilder<'a, remove_options_state::SetScope<S>> {
248 self._fields.1 = Option::Some(value.into());
249 RemoveOptionsBuilder {
250 _state: PhantomData,
251 _fields: self._fields,
252 _lifetime: PhantomData,
253 }
254 }
255}
256
257impl<'a, S> RemoveOptionsBuilder<'a, S>
258where
259 S: remove_options_state::State,
260 S::Keys: remove_options_state::IsSet,
261 S::Scope: remove_options_state::IsSet,
262{
263 pub fn build(self) -> RemoveOptions<'a> {
265 RemoveOptions {
266 keys: self._fields.0.unwrap(),
267 scope: self._fields.1.unwrap(),
268 extra_data: Default::default(),
269 }
270 }
271 pub fn build_with_data(
273 self,
274 extra_data: BTreeMap<
275 jacquard_common::deps::smol_str::SmolStr,
276 jacquard_common::types::value::Data<'a>,
277 >,
278 ) -> RemoveOptions<'a> {
279 RemoveOptions {
280 keys: self._fields.0.unwrap(),
281 scope: self._fields.1.unwrap(),
282 extra_data: Some(extra_data),
283 }
284 }
285}