Skip to main content

proto_blue_api/generated/com/atproto/server/
requestEmailUpdate.rs

1// Generated by atproto-codegen. Do not edit.
2//! Lexicon: com.atproto.server.requestEmailUpdate
3
4use serde::{Deserialize, Serialize};
5
6/// Request a token in order to update email.
7/// XRPC Procedure: com.atproto.server.requestEmailUpdate
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct Output {
11    pub token_required: bool,
12}
13
14/// Errors a `call()` on this method can return.
15#[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
29/// Execute the procedure.
30pub async fn call(
31    client: &proto_blue_xrpc::XrpcClient,
32    opts: Option<&proto_blue_xrpc::CallOptions>,
33) -> Result<Output, CallError> {
34    let qp_ref: Option<&proto_blue_xrpc::QueryParams> = None;
35    let response = match client
36        .procedure("com.atproto.server.requestEmailUpdate", qp_ref, None, opts)
37        .await
38    {
39        Ok(r) => r,
40        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
41        Err(e) => return Err(CallError::Transport(e)),
42    };
43    Ok(serde_json::from_value(response.data)?)
44}
45
46/// Register a typed handler for this procedure on an [`proto_blue_xrpc::XrpcServer`].
47#[cfg(feature = "server")]
48pub fn register<F, Fut>(
49    server: proto_blue_xrpc::XrpcServer,
50    handler: F,
51) -> proto_blue_xrpc::XrpcServer
52where
53    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
54    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>>
55        + Send
56        + 'static,
57{
58    let handler = std::sync::Arc::new(handler);
59    server.procedure("com.atproto.server.requestEmailUpdate", move |ctx| {
60        let handler = handler.clone();
61        async move {
62            let out = handler(ctx).await?;
63            let value = serde_json::to_value(&out).map_err(|e| {
64                proto_blue_xrpc::XrpcServerError::new(
65                    proto_blue_xrpc::ResponseType::InternalServerError,
66                    format!("output serialize: {e}"),
67                )
68            })?;
69            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
70        }
71    })
72}