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
4use serde::{Deserialize, Serialize};
5
6/// Delete an entire set. Attempting to delete a set that does not exist will result in an error.
7/// XRPC Procedure: tools.ozone.set.deleteSet
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Input {
11    pub name: String,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Output {
17}
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.procedure("tools.ozone.set.deleteSet", qp_ref, Some(body), opts).await {
49        Ok(r) => r,
50        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
51        Err(e) => return Err(CallError::Transport(e)),
52    };
53    Ok(serde_json::from_value(response.data)?)
54}
55
56/// Register a typed handler for this procedure on an [`XrpcServer`].
57#[cfg(feature = "server")]
58pub fn register<F, Fut>(
59server: proto_blue_xrpc::XrpcServer,
60handler: F,
61) -> proto_blue_xrpc::XrpcServer
62where
63    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
64    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
65{
66    let handler = std::sync::Arc::new(handler);
67    server.procedure("tools.ozone.set.deleteSet", move |ctx| {
68        let handler = handler.clone();
69        async move {
70            let input = match ctx.json_body()? {
71                Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InvalidRequest, format!("input deserialize: {e}")))?),
72                None => None,
73            };
74            let out = handler(ctx, input).await?;
75            let value = serde_json::to_value(&out)
76                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
77            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
78        }
79    })
80}
81