proto_blue_api/generated/tools/ozone/setting/
removeOptions.rs1#![allow(clippy::pedantic, clippy::nursery, clippy::all)]
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Input {
12 pub keys: Vec<proto_blue_syntax::Nsid>,
13 pub scope: String,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(rename_all = "camelCase")]
18pub struct Output {}
19
20#[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
35pub 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
44 .procedure(
45 "tools.ozone.setting.removeOptions",
46 qp_ref,
47 Some(body),
48 opts,
49 )
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#[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.setting.removeOptions", 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}