Skip to main content

proto_blue_api/generated/tools/ozone/setting/
removeOptions.rs

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