use std::ops::Deref; use ruma::{ api::client::uiaa::UiaaResponse, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, }; use crate::{service::appservice::RegistrationInfo, Error}; mod axum; /// A wrapper to convert an Axum request to Ruma data /// /// Named so because this converts from **A**xum to **R**uma. See also [`Ra`], /// which is roughly the inverse of this type. pub(crate) struct Ar { /// The Ruma type to deserialize the body into pub(crate) body: T, pub(crate) sender_user: Option, pub(crate) sender_device: Option, pub(crate) sender_servername: Option, // This is None when body is not a valid string pub(crate) json_body: Option, pub(crate) appservice_info: Option, } impl Ar { pub(crate) fn map_body(self, f: F) -> Ar where F: FnOnce(T) -> U, { let Ar { body, sender_user, sender_device, sender_servername, json_body, appservice_info, } = self; Ar { body: f(body), sender_user, sender_device, sender_servername, json_body, appservice_info, } } } impl Deref for Ar { type Target = T; fn deref(&self) -> &Self::Target { &self.body } } /// A wrapper to convert Ruma data to an Axum response /// /// Named so because this converts from **R**uma to **A**xum. See also [`Ar`], /// which is roughly the inverse of this type. #[derive(Clone)] pub(crate) struct Ra(pub(crate) T); impl From for Ra { fn from(t: T) -> Self { Self(t) } } impl From for Ra { fn from(t: Error) -> Self { t.to_response() } }