jacquard-api 0.10.2

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

fn _default_depth() -> std::option::Option<i64> {
    Some(6i64)
}

fn _default_parent_height() -> std::option::Option<i64> {
    Some(80i64)
}

#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetPostThread<'a> {
    ///Defaults to `6`. Min: 0. Max: 1000.
    #[serde(default = "_default_depth")]
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub depth: std::option::Option<i64>,
    ///Defaults to `80`. Min: 0. Max: 1000.
    #[serde(default = "_default_parent_height")]
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    pub parent_height: std::option::Option<i64>,
    #[serde(borrow)]
    pub uri: jacquard_common::types::string::AtUri<'a>,
}

pub mod get_post_thread_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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
    }
    /// 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 GetPostThreadBuilder<'a, S: get_post_thread_state::State> {
    _phantom_state: ::core::marker::PhantomData<fn() -> S>,
    __unsafe_private_named: (
        ::core::option::Option<i64>,
        ::core::option::Option<i64>,
        ::core::option::Option<jacquard_common::types::string::AtUri<'a>>,
    ),
    _phantom: ::core::marker::PhantomData<&'a ()>,
}

impl<'a> GetPostThread<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetPostThreadBuilder<'a, get_post_thread_state::Empty> {
        GetPostThreadBuilder::new()
    }
}

impl<'a> GetPostThreadBuilder<'a, get_post_thread_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        GetPostThreadBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: (None, None, None),
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S: get_post_thread_state::State> GetPostThreadBuilder<'a, S> {
    /// Set the `depth` field (optional)
    pub fn depth(mut self, value: impl Into<Option<i64>>) -> Self {
        self.__unsafe_private_named.0 = value.into();
        self
    }
    /// Set the `depth` field to an Option value (optional)
    pub fn maybe_depth(mut self, value: Option<i64>) -> Self {
        self.__unsafe_private_named.0 = value;
        self
    }
}

impl<'a, S: get_post_thread_state::State> GetPostThreadBuilder<'a, S> {
    /// Set the `parentHeight` field (optional)
    pub fn parent_height(mut self, value: impl Into<Option<i64>>) -> Self {
        self.__unsafe_private_named.1 = value.into();
        self
    }
    /// Set the `parentHeight` field to an Option value (optional)
    pub fn maybe_parent_height(mut self, value: Option<i64>) -> Self {
        self.__unsafe_private_named.1 = value;
        self
    }
}

impl<'a, S> GetPostThreadBuilder<'a, S>
where
    S: get_post_thread_state::State,
    S::Uri: get_post_thread_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<jacquard_common::types::string::AtUri<'a>>,
    ) -> GetPostThreadBuilder<'a, get_post_thread_state::SetUri<S>> {
        self.__unsafe_private_named.2 = ::core::option::Option::Some(value.into());
        GetPostThreadBuilder {
            _phantom_state: ::core::marker::PhantomData,
            __unsafe_private_named: self.__unsafe_private_named,
            _phantom: ::core::marker::PhantomData,
        }
    }
}

impl<'a, S> GetPostThreadBuilder<'a, S>
where
    S: get_post_thread_state::State,
    S::Uri: get_post_thread_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetPostThread<'a> {
        GetPostThread {
            depth: self.__unsafe_private_named.0,
            parent_height: self.__unsafe_private_named.1,
            uri: self.__unsafe_private_named.2.unwrap(),
        }
    }
}

#[jacquard_derive::lexicon]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct GetPostThreadOutput<'a> {
    #[serde(borrow)]
    pub thread: GetPostThreadOutputThread<'a>,
    #[serde(skip_serializing_if = "std::option::Option::is_none")]
    #[serde(borrow)]
    pub threadgate: std::option::Option<crate::app_bsky::feed::ThreadgateView<'a>>,
}

#[jacquard_derive::open_union]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    jacquard_derive::IntoStatic
)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetPostThreadOutputThread<'a> {
    #[serde(rename = "app.bsky.feed.defs#threadViewPost")]
    ThreadViewPost(Box<crate::app_bsky::feed::ThreadViewPost<'a>>),
    #[serde(rename = "app.bsky.feed.defs#notFoundPost")]
    NotFoundPost(Box<crate::app_bsky::feed::NotFoundPost<'a>>),
    #[serde(rename = "app.bsky.feed.defs#blockedPost")]
    BlockedPost(Box<crate::app_bsky::feed::BlockedPost<'a>>),
}

#[jacquard_derive::open_union]
#[derive(
    serde::Serialize,
    serde::Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    jacquard_derive::IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GetPostThreadError<'a> {
    #[serde(rename = "NotFound")]
    NotFound(std::option::Option<jacquard_common::CowStr<'a>>),
}

impl core::fmt::Display for GetPostThreadError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::NotFound(msg) => {
                write!(f, "NotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for
///app.bsky.feed.getPostThread
pub struct GetPostThreadResponse;
impl jacquard_common::xrpc::XrpcResp for GetPostThreadResponse {
    const NSID: &'static str = "app.bsky.feed.getPostThread";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = GetPostThreadOutput<'de>;
    type Err<'de> = GetPostThreadError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for GetPostThread<'a> {
    const NSID: &'static str = "app.bsky.feed.getPostThread";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetPostThreadResponse;
}

/// Endpoint type for
///app.bsky.feed.getPostThread
pub struct GetPostThreadRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetPostThreadRequest {
    const PATH: &'static str = "/xrpc/app.bsky.feed.getPostThread";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetPostThread<'de>;
    type Response = GetPostThreadResponse;
}