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