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.procedure("com.atproto.server.requestEmailUpdate", qp_ref, None, opts).await {
36        Ok(r) => r,
37        Err(proto_blue_xrpc::Error::Xrpc(x)) => return Err(map_xrpc_error(x)),
38        Err(e) => return Err(CallError::Transport(e)),
39    };
40    Ok(serde_json::from_value(response.data)?)
41}
42
43/// Register a typed handler for this procedure on an [`XrpcServer`].
44#[cfg(feature = "server")]
45pub fn register<F, Fut>(
46server: proto_blue_xrpc::XrpcServer,
47handler: F,
48) -> proto_blue_xrpc::XrpcServer
49where
50    F: Fn(proto_blue_xrpc::HandlerContext) -> Fut + Send + Sync + 'static,
51    Fut: std::future::Future<Output = Result<Output, proto_blue_xrpc::XrpcServerError>> + Send + 'static,
52{
53    let handler = std::sync::Arc::new(handler);
54    server.procedure("com.atproto.server.requestEmailUpdate", move |ctx| {
55        let handler = handler.clone();
56        async move {
57            let out = handler(ctx).await?;
58            let value = serde_json::to_value(&out)
59                .map_err(|e| proto_blue_xrpc::XrpcServerError::new(proto_blue_xrpc::ResponseType::InternalServerError, format!("output serialize: {e}")))?;
60            Ok::<_, proto_blue_xrpc::XrpcServerError>(value)
61        }
62    })
63}
64