jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.live.subscribeSegments
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

use crate::place_stream::live::subscribe_segments;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::bytes::Bytes;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct SubscribeSegments<S: BosStr = DefaultStr> {
    pub streamer: S,
}

#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SubscribeSegmentsMessage<S: BosStr = DefaultStr> {
    #[serde(rename = "#segment")]
    Segment(Box<subscribe_segments::Segment>),
}

impl<S: BosStr> SubscribeSegmentsMessage<S> {
    /// Decode a framed DAG-CBOR message (header + body).
    pub fn decode_framed<'de>(
        bytes: &'de [u8],
    ) -> Result<SubscribeSegmentsMessage<S>, jacquard_common::error::DecodeError>
    where
        S: serde::Deserialize<'de>,
    {
        let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(bytes)?;
        match header.t.as_str() {
            "#segment" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(body)?;
                Ok(Self::Segment(Box::new(variant)))
            }
            unknown => Err(jacquard_common::error::DecodeError::UnknownEventType(
                unknown.into(),
            )),
        }
    }
}

pub type Segment = Bytes;
///Stream response type for
///place.stream.live.subscribeSegments
pub struct SubscribeSegmentsStream;
impl jacquard_common::xrpc::SubscriptionResp for SubscribeSegmentsStream {
    const NSID: &'static str = "place.stream.live.subscribeSegments";
    const ENCODING: jacquard_common::xrpc::MessageEncoding =
        jacquard_common::xrpc::MessageEncoding::Json;
    type Message<S: BosStr> = SubscribeSegmentsMessage<S>;
    type Error = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcSubscription for SubscribeSegments<S> {
    const NSID: &'static str = "place.stream.live.subscribeSegments";
    const ENCODING: jacquard_common::xrpc::MessageEncoding =
        jacquard_common::xrpc::MessageEncoding::Json;
    type Stream = SubscribeSegmentsStream;
}

pub struct SubscribeSegmentsEndpoint;
impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeSegmentsEndpoint {
    const PATH: &'static str = "/xrpc/place.stream.live.subscribeSegments";
    const ENCODING: jacquard_common::xrpc::MessageEncoding =
        jacquard_common::xrpc::MessageEncoding::Json;
    type Params<S: BosStr> = SubscribeSegments<S>;
    type Stream = SubscribeSegmentsStream;
}

pub mod subscribe_segments_state {

    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
    #[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 Streamer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Streamer = Unset;
    }
    ///State transition - sets the `streamer` field to Set
    pub struct SetStreamer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStreamer<St> {}
    impl<St: State> State for SetStreamer<St> {
        type Streamer = Set<members::streamer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `streamer` field
        pub struct streamer(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SubscribeSegmentsBuilder<S: BosStr, St: subscribe_segments_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>,),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> SubscribeSegments<S> {
    /// Create a new builder for this type.
    pub fn new() -> SubscribeSegmentsBuilder<S, subscribe_segments_state::Empty> {
        SubscribeSegmentsBuilder::new()
    }
}

impl<S: BosStr> SubscribeSegmentsBuilder<S, subscribe_segments_state::Empty> {
    /// Create a new builder with all fields unset.
    pub fn new() -> Self {
        SubscribeSegmentsBuilder {
            _state: PhantomData,
            _fields: (None,),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> SubscribeSegmentsBuilder<S, St>
where
    St: subscribe_segments_state::State,
    St::Streamer: subscribe_segments_state::IsUnset,
{
    /// Set the `streamer` field (required)
    pub fn streamer(
        mut self,
        value: impl Into<S>,
    ) -> SubscribeSegmentsBuilder<S, subscribe_segments_state::SetStreamer<St>> {
        self._fields.0 = Option::Some(value.into());
        SubscribeSegmentsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> SubscribeSegmentsBuilder<S, St>
where
    St: subscribe_segments_state::State,
    St::Streamer: subscribe_segments_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SubscribeSegments<S> {
        SubscribeSegments {
            streamer: self._fields.0.unwrap(),
        }
    }
}