proto_blue_api/generated/tools/ozone/set/
addValues.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 name: String,
13 pub values: Vec<String>,
14}
15
16#[derive(Debug, thiserror::Error)]
18pub enum CallError {
19 #[error("{0}")]
20 Xrpc(proto_blue_xrpc::XrpcError),
21 #[error(transparent)]
22 Transport(#[from] proto_blue_xrpc::Error),
23 #[error(transparent)]
24 Json(#[from] serde_json::Error),
25}
26
27fn map_xrpc_error(err: proto_blue_xrpc::XrpcError) -> CallError {
28 CallError::Xrpc(err)
29}
30
31pub async fn call(
33 client: &proto_blue_xrpc::XrpcClient,
34 input: &Input,
35 opts: Option<&proto_blue_xrpc::CallOptions>,
36) -> Result<serde_json::Value, CallError> {
37 let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
38 let body = proto_blue_xrpc::XrpcBody::Json(serde_json::to_value(input)?);
39 let response = match client
40 .procedure("tools.ozone.set.addValues", qp_ref, Some(body), opts)
41 .await
42 {
43 Ok(r) => r,
44 Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
45 Err(e) => return Err(CallError::Transport(e)),
46 };
47 Ok(response.data)
48}
49
50#[cfg(feature = "server")]
52pub fn register<F, Fut>(
53 server: proto_blue_xrpc::XrpcServer,
54 handler: F,
55) -> proto_blue_xrpc::XrpcServer
56where
57 F: Fn(proto_blue_xrpc::HandlerContext, Option<Input>) -> Fut + Send + Sync + 'static,
58 Fut: std::future::Future<Output = Result<serde_json::Value, proto_blue_xrpc::XrpcServerError>>
59 + Send
60 + 'static,
61{
62 let handler = std::sync::Arc::new(handler);
63 server.procedure("tools.ozone.set.addValues", move |ctx| {
64 let handler = handler.clone();
65 async move {
66 let input = match ctx.json_body()? {
67 Some(v) => Some(serde_json::from_value::<Input>(v).map_err(|e| {
68 proto_blue_xrpc::XrpcServerError::new(
69 proto_blue_xrpc::ResponseType::InvalidRequest,
70 format!("input deserialize: {e}"),
71 )
72 })?),
73 None => None,
74 };
75 let out = handler(ctx, input).await?;
76 Ok::<_, proto_blue_xrpc::XrpcServerError>(out)
77 }
78 })
79}