jacquard_api/place_stream/multistream/
put_target.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::{RecordKey, Rkey};
15use jacquard_derive::{IntoStatic, lexicon, open_union};
16use serde::{Serialize, Deserialize};
17use crate::place_stream::multistream::TargetView;
18use crate::place_stream::multistream::target::Target;
19
20#[lexicon]
21#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
22#[serde(rename_all = "camelCase")]
23pub struct PutTarget<'a> {
24 #[serde(borrow)]
25 pub multistream_target: Target<'a>,
26 #[serde(skip_serializing_if = "Option::is_none")]
28 #[serde(borrow)]
29 pub rkey: Option<RecordKey<Rkey<'a>>>,
30}
31
32
33#[lexicon]
34#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
35#[serde(rename_all = "camelCase")]
36pub struct PutTargetOutput<'a> {
37 #[serde(flatten)]
38 #[serde(borrow)]
39 pub value: TargetView<'a>,
40}
41
42
43#[open_union]
44#[derive(
45 Serialize,
46 Deserialize,
47 Debug,
48 Clone,
49 PartialEq,
50 Eq,
51 thiserror::Error,
52 miette::Diagnostic,
53 IntoStatic
54)]
55
56#[serde(tag = "error", content = "message")]
57#[serde(bound(deserialize = "'de: 'a"))]
58pub enum PutTargetError<'a> {
59 #[serde(rename = "InvalidTargetUrl")]
61 InvalidTargetUrl(Option<CowStr<'a>>),
62}
63
64impl core::fmt::Display for PutTargetError<'_> {
65 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
66 match self {
67 Self::InvalidTargetUrl(msg) => {
68 write!(f, "InvalidTargetUrl")?;
69 if let Some(msg) = msg {
70 write!(f, ": {}", msg)?;
71 }
72 Ok(())
73 }
74 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
75 }
76 }
77}
78
79pub struct PutTargetResponse;
81impl jacquard_common::xrpc::XrpcResp for PutTargetResponse {
82 const NSID: &'static str = "place.stream.multistream.putTarget";
83 const ENCODING: &'static str = "application/json";
84 type Output<'de> = PutTargetOutput<'de>;
85 type Err<'de> = PutTargetError<'de>;
86}
87
88impl<'a> jacquard_common::xrpc::XrpcRequest for PutTarget<'a> {
89 const NSID: &'static str = "place.stream.multistream.putTarget";
90 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
91 "application/json",
92 );
93 type Response = PutTargetResponse;
94}
95
96pub struct PutTargetRequest;
98impl jacquard_common::xrpc::XrpcEndpoint for PutTargetRequest {
99 const PATH: &'static str = "/xrpc/place.stream.multistream.putTarget";
100 const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
101 "application/json",
102 );
103 type Request<'de> = PutTarget<'de>;
104 type Response = PutTargetResponse;
105}
106
107pub mod put_target_state {
108
109 pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
110 #[allow(unused)]
111 use ::core::marker::PhantomData;
112 mod sealed {
113 pub trait Sealed {}
114 }
115 pub trait State: sealed::Sealed {
117 type MultistreamTarget;
118 }
119 pub struct Empty(());
121 impl sealed::Sealed for Empty {}
122 impl State for Empty {
123 type MultistreamTarget = Unset;
124 }
125 pub struct SetMultistreamTarget<S: State = Empty>(PhantomData<fn() -> S>);
127 impl<S: State> sealed::Sealed for SetMultistreamTarget<S> {}
128 impl<S: State> State for SetMultistreamTarget<S> {
129 type MultistreamTarget = Set<members::multistream_target>;
130 }
131 #[allow(non_camel_case_types)]
133 pub mod members {
134 pub struct multistream_target(());
136 }
137}
138
139pub struct PutTargetBuilder<'a, S: put_target_state::State> {
141 _state: PhantomData<fn() -> S>,
142 _fields: (Option<Target<'a>>, Option<RecordKey<Rkey<'a>>>),
143 _lifetime: PhantomData<&'a ()>,
144}
145
146impl<'a> PutTarget<'a> {
147 pub fn new() -> PutTargetBuilder<'a, put_target_state::Empty> {
149 PutTargetBuilder::new()
150 }
151}
152
153impl<'a> PutTargetBuilder<'a, put_target_state::Empty> {
154 pub fn new() -> Self {
156 PutTargetBuilder {
157 _state: PhantomData,
158 _fields: (None, None),
159 _lifetime: PhantomData,
160 }
161 }
162}
163
164impl<'a, S> PutTargetBuilder<'a, S>
165where
166 S: put_target_state::State,
167 S::MultistreamTarget: put_target_state::IsUnset,
168{
169 pub fn multistream_target(
171 mut self,
172 value: impl Into<Target<'a>>,
173 ) -> PutTargetBuilder<'a, put_target_state::SetMultistreamTarget<S>> {
174 self._fields.0 = Option::Some(value.into());
175 PutTargetBuilder {
176 _state: PhantomData,
177 _fields: self._fields,
178 _lifetime: PhantomData,
179 }
180 }
181}
182
183impl<'a, S: put_target_state::State> PutTargetBuilder<'a, S> {
184 pub fn rkey(mut self, value: impl Into<Option<RecordKey<Rkey<'a>>>>) -> Self {
186 self._fields.1 = value.into();
187 self
188 }
189 pub fn maybe_rkey(mut self, value: Option<RecordKey<Rkey<'a>>>) -> Self {
191 self._fields.1 = value;
192 self
193 }
194}
195
196impl<'a, S> PutTargetBuilder<'a, S>
197where
198 S: put_target_state::State,
199 S::MultistreamTarget: put_target_state::IsSet,
200{
201 pub fn build(self) -> PutTarget<'a> {
203 PutTarget {
204 multistream_target: self._fields.0.unwrap(),
205 rkey: self._fields.1,
206 extra_data: Default::default(),
207 }
208 }
209 pub fn build_with_data(
211 self,
212 extra_data: BTreeMap<
213 jacquard_common::deps::smol_str::SmolStr,
214 jacquard_common::types::value::Data<'a>,
215 >,
216 ) -> PutTarget<'a> {
217 PutTarget {
218 multistream_target: self._fields.0.unwrap(),
219 rkey: self._fields.1,
220 extra_data: Some(extra_data),
221 }
222 }
223}