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