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