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<String>,
12    pub scope: String,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16#[serde(rename_all = "camelCase")]
17pub struct Output {
18}
19
20/// Errors a `call()` on this method can return.
21#[derive(Debug, thiserror::Error)]
22pub enum CallError {
23    #[error("{0}")]
24    Xrpc(proto_blue_xrpc::XrpcError),
25    #[error(transparent)]
26    Transport(#[from] proto_blue_xrpc::Error),
27    #[error(transparent)]
28    Json(#[from] serde_json::Error),
29}
30
31fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
32    CallError::Xrpc(err)
33}
34
35/// Execute the procedure.
36pub async fn call(
37    client: &proto_blue_xrpc::XrpcClient,
38    input: &Input,
39    opts: Option<&proto_blue_xrpc::CallOptions>,
40) -> Result<Output, CallError> {
41    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
42    let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
43    let response = match client.procedure("tools.ozone.setting.removeOptions", qp_ref, Some(body), opts).await {
44        Ok(r) => r,
45        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
46        Err(e) => return Err(CallError::Transport(e)),
47    };
48    Ok(serde_json::from_value(response.data)?)
49}
50
51/// Register a typed handler for this procedure on an [`XrpcServer`].
52#[cfg(feature = "server")]
53pub fn register<F, Fut>(
54server: proto_blue_xrpc::XrpcServer,
55handler: F,
56) -> proto_blue_xrpc::XrpcServer
57where
58    F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
59    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
60{
61    let handler = std::sync::Arc::new(handler);
62    server.procedure("tools.ozone.setting.removeOptions", move |ctx| {
63        let handler = handler.clone();
64        async move {
65            let input = match ctx.json_body()? {
66                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}")))?),
67                None => None,
68            };
69            let out = handler(ctx, input).await?;
70            let value = serde_json::to_value(&out)
71                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
72            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
73        }
74    })
75}
76