#![doc(html_favicon_url = "https://www.ruma.io/favicon.ico")]
#![doc(html_logo_url = "https://www.ruma.io/images/logo.png")]
#![warn(missing_docs)]
use serde::{Deserialize, Serialize};
pub mod event;
pub mod query;
pub mod thirdparty;
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(not(feature = "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(feature = "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(feature = "unstable-exhaustive-types"), non_exhaustive)]
pub struct Registration {
pub id: String,
pub url: 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>>,
}
#[derive(Debug)]
#[allow(clippy::exhaustive_structs)]
pub struct RegistrationInit {
pub id: String,
pub url: 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 }
}
}