Skip to main content

proto_blue_api/generated/tools/ozone/set/
deleteSet.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: tools.ozone.set.deleteSet
3#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7/// Delete an entire set. Attempting to delete a set that does not exist will result in an error.
8/// XRPC Procedure: tools.ozone.set.deleteSet
9#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Input {
12    pub name: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Output {}
18
19/// Errors a `call()` on this method can return.
20#[derive(Debug, thiserror::Error)]
21pub enum CallError {
22    /// set with the given name does not exist
23    #[error("SetNotFound")]
24    SetNotFound,
25    #[error("{0}")]
26    Xrpc(proto_blue_xrpc::XrpcError),
27    #[error(transparent)]
28    Transport(#[from] proto_blue_xrpc::Error),
29    #[error(transparent)]
30    Json(#[from] serde_json::Error),
31}
32
33fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
34    match err.error.as_deref() {
35        Some("SetNotFound") => CallError::SetNotFound,
36        _ => CallError::Xrpc(err),
37    }
38}
39
40/// Execute the procedure.
41pub async fn call(
42    client: &proto_blue_xrpc::XrpcClient,
43    input: &Input,
44    opts: Option<&proto_blue_xrpc::CallOptions>,
45) -> Result<Output, CallError> {
46    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
47    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
48    let response = match client
49        .procedure("tools.ozone.set.deleteSet", qp_ref, Some(body), opts)
50        .await
51    {
52        Ok(r) => r,
53        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
54        Err(e) => return Err(CallError::Transport(e)),
55    };
56    Ok(serde_json::from_value(response.data)?)
57}
58
59/// Register a typed handler for this procedure on an [`proto_blue_xrpc::XrpcServer`].
60#[cfg(feature = "server")]
61pub fn register<F, Fut>(
62    server: proto_blue_xrpc::XrpcServer,
63    handler: F,
64) -> proto_blue_xrpc::XrpcServer
65where
66    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
67    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
68        + Send
69        + 'static,
70{
71    let handler = std::sync::Arc::new(handler);
72    server.procedure("tools.ozone.set.deleteSet", move |ctx| {
73        let handler = handler.clone();
74        async move {
75            let input = match ctx.json_body()? {
76                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
77                    proto_blue_xrpc::XrpcServerError::new(
78                        proto_blue_xrpc::ResponseType::InvalidRequest,
79                        format!("input deserialize: {e}"),
80                    )
81                })?),
82                None => None,
83            };
84            let out = handler(ctx, input).await?;
85            let value = serde_json::to_value(&out).map_err(|e| {
86                proto_blue_xrpc::XrpcServerError::new(
87                    proto_blue_xrpc::ResponseType::InternalServerError,
88                    format!("output serialize: {e}"),
89                )
90            })?;
91            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
92        }
93    })
94}