#![doc(html_favicon_url = "https://ruma.dev/favicon.ico")]
#![doc(html_logo_url = "https://ruma.dev/images/logo.png")]
#![warn(missing_docs)]
use serde::{Deserialize, Serialize};
pub mod event;
pub mod ping;
pub mod query;
pub mod thirdparty;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct Namespace {
pub exclusive: bool,
pub regex: String,
}
impl Namespace {
pub fn new(exclusive: bool, regex: String) -> Self {
Namespace { exclusive, regex }
}
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct Namespaces {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub users: Vec<Namespace>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub aliases: Vec<Namespace>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rooms: Vec<Namespace>,
}
impl Namespaces {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct Registration {
pub id: String,
#[serde(deserialize_with = "Option::deserialize")]
pub url: Option<String>,
pub as_token: String,
pub hs_token: String,
pub sender_localpart: String,
pub namespaces: Namespaces,
#[serde(skip_serializing_if = "Option::is_none")]
pub rate_limited: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub protocols: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "ruma_common::serde::is_default")]
pub receive_ephemeral: bool,
}
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct RegistrationInit {
pub id: String,
pub url: Option<String>,
pub as_token: String,
pub hs_token: String,
pub sender_localpart: String,
pub namespaces: Namespaces,
pub rate_limited: Option<bool>,
pub protocols: Option<Vec<String>>,
}
impl From<RegistrationInit> for Registration {
fn from(init: RegistrationInit) -> Self {
let RegistrationInit {
id,
url,
as_token,
hs_token,
sender_localpart,
namespaces,
rate_limited,
protocols,
} = init;
Self {
id,
url,
as_token,
hs_token,
sender_localpart,
namespaces,
rate_limited,
protocols,
receive_ephemeral: false,
}
}
}