Skip to main content

jacquard_api/place_stream/live/
subscribe_segments.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.live.subscribeSegments
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[allow(unused_imports)]
9use core::marker::PhantomData;
10use jacquard_common::CowStr;
11use jacquard_common::deps::bytes::Bytes;
12use jacquard_derive::{IntoStatic, open_union};
13use serde::{Serialize, Deserialize};
14use crate::place_stream::live::subscribe_segments;
15
16#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
17#[serde(rename_all = "camelCase")]
18pub struct SubscribeSegments<'a> {
19    #[serde(borrow)]
20    pub streamer: CowStr<'a>,
21}
22
23
24#[open_union]
25#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
26#[serde(tag = "$type")]
27#[serde(bound(deserialize = "'de: 'a"))]
28pub enum SubscribeSegmentsMessage<'a> {
29    #[serde(rename = "#segment")]
30    Segment(Box<subscribe_segments::Segment>),
31}
32
33impl<'a> SubscribeSegmentsMessage<'a> {
34    /// Decode a framed DAG-CBOR message (header + body).
35    pub fn decode_framed<'de: 'a>(
36        bytes: &'de [u8],
37    ) -> Result<SubscribeSegmentsMessage<'a>, jacquard_common::error::DecodeError> {
38        let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(
39            bytes,
40        )?;
41        match header.t.as_str() {
42            "#segment" => {
43                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
44                    body,
45                )?;
46                Ok(Self::Segment(Box::new(variant)))
47            }
48            unknown => {
49                Err(
50                    jacquard_common::error::DecodeError::UnknownEventType(unknown.into()),
51                )
52            }
53        }
54    }
55}
56
57pub type Segment = Bytes;
58///Stream response type for
59///place.stream.live.subscribeSegments
60pub struct SubscribeSegmentsStream;
61impl jacquard_common::xrpc::SubscriptionResp for SubscribeSegmentsStream {
62    const NSID: &'static str = "place.stream.live.subscribeSegments";
63    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
64    type Message<'de> = SubscribeSegmentsMessage<'de>;
65    type Error<'de> = jacquard_common::xrpc::GenericError<'de>;
66}
67
68impl<'a> jacquard_common::xrpc::XrpcSubscription for SubscribeSegments<'a> {
69    const NSID: &'static str = "place.stream.live.subscribeSegments";
70    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
71    type Stream = SubscribeSegmentsStream;
72}
73
74pub struct SubscribeSegmentsEndpoint;
75impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeSegmentsEndpoint {
76    const PATH: &'static str = "/xrpc/place.stream.live.subscribeSegments";
77    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
78    type Params<'de> = SubscribeSegments<'de>;
79    type Stream = SubscribeSegmentsStream;
80}
81
82pub mod subscribe_segments_state {
83
84    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
85    #[allow(unused)]
86    use ::core::marker::PhantomData;
87    mod sealed {
88        pub trait Sealed {}
89    }
90    /// State trait tracking which required fields have been set
91    pub trait State: sealed::Sealed {
92        type Streamer;
93    }
94    /// Empty state - all required fields are unset
95    pub struct Empty(());
96    impl sealed::Sealed for Empty {}
97    impl State for Empty {
98        type Streamer = Unset;
99    }
100    ///State transition - sets the `streamer` field to Set
101    pub struct SetStreamer<S: State = Empty>(PhantomData<fn() -> S>);
102    impl<S: State> sealed::Sealed for SetStreamer<S> {}
103    impl<S: State> State for SetStreamer<S> {
104        type Streamer = Set<members::streamer>;
105    }
106    /// Marker types for field names
107    #[allow(non_camel_case_types)]
108    pub mod members {
109        ///Marker type for the `streamer` field
110        pub struct streamer(());
111    }
112}
113
114/// Builder for constructing an instance of this type
115pub struct SubscribeSegmentsBuilder<'a, S: subscribe_segments_state::State> {
116    _state: PhantomData<fn() -> S>,
117    _fields: (Option<CowStr<'a>>,),
118    _lifetime: PhantomData<&'a ()>,
119}
120
121impl<'a> SubscribeSegments<'a> {
122    /// Create a new builder for this type
123    pub fn new() -> SubscribeSegmentsBuilder<'a, subscribe_segments_state::Empty> {
124        SubscribeSegmentsBuilder::new()
125    }
126}
127
128impl<'a> SubscribeSegmentsBuilder<'a, subscribe_segments_state::Empty> {
129    /// Create a new builder with all fields unset
130    pub fn new() -> Self {
131        SubscribeSegmentsBuilder {
132            _state: PhantomData,
133            _fields: (None,),
134            _lifetime: PhantomData,
135        }
136    }
137}
138
139impl<'a, S> SubscribeSegmentsBuilder<'a, S>
140where
141    S: subscribe_segments_state::State,
142    S::Streamer: subscribe_segments_state::IsUnset,
143{
144    /// Set the `streamer` field (required)
145    pub fn streamer(
146        mut self,
147        value: impl Into<CowStr<'a>>,
148    ) -> SubscribeSegmentsBuilder<'a, subscribe_segments_state::SetStreamer<S>> {
149        self._fields.0 = Option::Some(value.into());
150        SubscribeSegmentsBuilder {
151            _state: PhantomData,
152            _fields: self._fields,
153            _lifetime: PhantomData,
154        }
155    }
156}
157
158impl<'a, S> SubscribeSegmentsBuilder<'a, S>
159where
160    S: subscribe_segments_state::State,
161    S::Streamer: subscribe_segments_state::IsSet,
162{
163    /// Build the final struct
164    pub fn build(self) -> SubscribeSegments<'a> {
165        SubscribeSegments {
166            streamer: self._fields.0.unwrap(),
167        }
168    }
169}