ruma-common: Make most public types non-exhaustive
This commit is contained in:
parent
f9e76358a1
commit
324d339f06
@ -7,6 +7,7 @@ use strum::{Display, EnumString};
|
|||||||
|
|
||||||
/// A description of a user's connectivity and availability for chat.
|
/// A description of a user's connectivity and availability for chat.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, Display, EnumString, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[strum(serialize_all = "snake_case")]
|
#[strum(serialize_all = "snake_case")]
|
||||||
pub enum PresenceState {
|
pub enum PresenceState {
|
||||||
|
@ -18,7 +18,11 @@ pub use self::{
|
|||||||
///
|
///
|
||||||
/// For example, some rules may only be applied for messages from a particular sender, a particular
|
/// For example, some rules may only be applied for messages from a particular sender, a particular
|
||||||
/// room, or by default. The push ruleset contains the entire set of scopes and rules.
|
/// room, or by default. The push ruleset contains the entire set of scopes and rules.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
///
|
||||||
|
/// To create an instance of this type, use its `Default` implementation and set the fields you
|
||||||
|
/// need.
|
||||||
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct Ruleset {
|
pub struct Ruleset {
|
||||||
/// These rules configure behavior for (unencrypted) messages that match certain patterns.
|
/// These rules configure behavior for (unencrypted) messages that match certain patterns.
|
||||||
pub content: Vec<PatternedPushRule>,
|
pub content: Vec<PatternedPushRule>,
|
||||||
@ -46,7 +50,11 @@ pub struct Ruleset {
|
|||||||
///
|
///
|
||||||
/// These rules are stored on the user's homeserver. They are manually configured by the user, who
|
/// These rules are stored on the user's homeserver. They are manually configured by the user, who
|
||||||
/// can create and view them via the Client/Server API.
|
/// can create and view them via the Client/Server API.
|
||||||
|
///
|
||||||
|
/// To create an instance of this type, first create a `PushRuleInit` and convert it via
|
||||||
|
/// `PushRule::from` / `.into()`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct PushRule {
|
pub struct PushRule {
|
||||||
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
@ -61,10 +69,40 @@ pub struct PushRule {
|
|||||||
pub rule_id: String,
|
pub rule_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initial set of fields of `PushRule`.
|
||||||
|
///
|
||||||
|
/// This struct will not be updated even if additional fields are added to `PushRule` in a new
|
||||||
|
/// (non-breaking) release of the Matrix specification.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct PushRuleInit {
|
||||||
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
|
pub actions: Vec<Action>,
|
||||||
|
|
||||||
|
/// Whether this is a default rule, or has been set explicitly.
|
||||||
|
pub default: bool,
|
||||||
|
|
||||||
|
/// Whether the push rule is enabled or not.
|
||||||
|
pub enabled: bool,
|
||||||
|
|
||||||
|
/// The ID of this rule.
|
||||||
|
pub rule_id: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PushRuleInit> for PushRule {
|
||||||
|
fn from(init: PushRuleInit) -> Self {
|
||||||
|
let PushRuleInit { actions, default, enabled, rule_id } = init;
|
||||||
|
Self { actions, default, enabled, rule_id }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Like `PushRule`, but with an additional `conditions` field.
|
/// Like `PushRule`, but with an additional `conditions` field.
|
||||||
///
|
///
|
||||||
/// Only applicable to underride and override rules.
|
/// Only applicable to underride and override rules.
|
||||||
|
///
|
||||||
|
/// To create an instance of this type, first create a `ConditionalPushRuleInit` and convert it via
|
||||||
|
/// `ConditionalPushRule::from` / `.into()`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct ConditionalPushRule {
|
pub struct ConditionalPushRule {
|
||||||
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
@ -84,10 +122,45 @@ pub struct ConditionalPushRule {
|
|||||||
pub conditions: Vec<PushCondition>,
|
pub conditions: Vec<PushCondition>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initial set of fields of `ConditionalPushRule`.
|
||||||
|
///
|
||||||
|
/// This struct will not be updated even if additional fields are added to `ConditionalPushRule` in
|
||||||
|
/// a new (non-breaking) release of the Matrix specification.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ConditionalPushRuleInit {
|
||||||
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
|
pub actions: Vec<Action>,
|
||||||
|
|
||||||
|
/// Whether this is a default rule, or has been set explicitly.
|
||||||
|
pub default: bool,
|
||||||
|
|
||||||
|
/// Whether the push rule is enabled or not.
|
||||||
|
pub enabled: bool,
|
||||||
|
|
||||||
|
/// The ID of this rule.
|
||||||
|
pub rule_id: String,
|
||||||
|
|
||||||
|
/// The conditions that must hold true for an event in order for a rule to be applied to an event.
|
||||||
|
///
|
||||||
|
/// A rule with no conditions always matches.
|
||||||
|
pub conditions: Vec<PushCondition>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ConditionalPushRuleInit> for ConditionalPushRule {
|
||||||
|
fn from(init: ConditionalPushRuleInit) -> Self {
|
||||||
|
let ConditionalPushRuleInit { actions, default, enabled, rule_id, conditions } = init;
|
||||||
|
Self { actions, default, enabled, rule_id, conditions }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Like `PushRule`, but with an additional `pattern` field.
|
/// Like `PushRule`, but with an additional `pattern` field.
|
||||||
///
|
///
|
||||||
/// Only applicable to content rules.
|
/// Only applicable to content rules.
|
||||||
|
///
|
||||||
|
/// To create an instance of this type, first create a `PatternedPushRuleInit` and convert it via
|
||||||
|
/// `PatternedPushRule::from` / `.into()`.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct PatternedPushRule {
|
pub struct PatternedPushRule {
|
||||||
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
@ -104,3 +177,32 @@ pub struct PatternedPushRule {
|
|||||||
/// The glob-style pattern to match against.
|
/// The glob-style pattern to match against.
|
||||||
pub pattern: String,
|
pub pattern: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Initial set of fields of `PatterenedPushRule`.
|
||||||
|
///
|
||||||
|
/// This struct will not be updated even if additional fields are added to `PatterenedPushRule` in a new
|
||||||
|
/// (non-breaking) release of the Matrix specification.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct PatternedPushRuleInit {
|
||||||
|
/// Actions to determine if and how a notification is delivered for events matching this rule.
|
||||||
|
pub actions: Vec<Action>,
|
||||||
|
|
||||||
|
/// Whether this is a default rule, or has been set explicitly.
|
||||||
|
pub default: bool,
|
||||||
|
|
||||||
|
/// Whether the push rule is enabled or not.
|
||||||
|
pub enabled: bool,
|
||||||
|
|
||||||
|
/// The ID of this rule.
|
||||||
|
pub rule_id: String,
|
||||||
|
|
||||||
|
/// The glob-style pattern to match against.
|
||||||
|
pub pattern: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PatternedPushRuleInit> for PatternedPushRule {
|
||||||
|
fn from(init: PatternedPushRuleInit) -> Self {
|
||||||
|
let PatternedPushRuleInit { actions, default, enabled, rule_id, pattern } = init;
|
||||||
|
Self { actions, default, enabled, rule_id, pattern }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,6 +26,7 @@ pub enum Action {
|
|||||||
|
|
||||||
/// The `set_tweak` action.
|
/// The `set_tweak` action.
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
#[serde(from = "tweak_serde::Tweak", into = "tweak_serde::Tweak")]
|
#[serde(from = "tweak_serde::Tweak", into = "tweak_serde::Tweak")]
|
||||||
pub enum Tweak {
|
pub enum Tweak {
|
||||||
/// A string representing the sound to be played when this notification arrives.
|
/// A string representing the sound to be played when this notification arrives.
|
||||||
|
@ -6,11 +6,17 @@ use std::{
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{Action, ConditionalPushRule, PatternedPushRule, PushCondition, PushRule};
|
use super::{
|
||||||
|
Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, PatternedPushRuleInit,
|
||||||
|
PushCondition, PushRule, PushRuleInit,
|
||||||
|
};
|
||||||
|
|
||||||
/// Like `PushRule`, but may represent any kind of push rule
|
/// Like `PushRule`, but may represent any kind of push rule
|
||||||
/// thanks to `pattern` and `conditions` being optional.
|
/// thanks to `pattern` and `conditions` being optional.
|
||||||
|
///
|
||||||
|
/// To create an instance of this type, use one of its `From` implementations.
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct AnyPushRule {
|
pub struct AnyPushRule {
|
||||||
/// The actions to perform when this rule is matched.
|
/// The actions to perform when this rule is matched.
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
@ -55,6 +61,27 @@ impl From<ConditionalPushRule> for AnyPushRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<PushRuleInit> for AnyPushRule {
|
||||||
|
fn from(init: PushRuleInit) -> Self {
|
||||||
|
let PushRuleInit { actions, default, enabled, rule_id } = init;
|
||||||
|
Self { actions, default, enabled, rule_id, pattern: None, conditions: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ConditionalPushRuleInit> for AnyPushRule {
|
||||||
|
fn from(init: ConditionalPushRuleInit) -> Self {
|
||||||
|
let ConditionalPushRuleInit { actions, default, enabled, rule_id, conditions } = init;
|
||||||
|
Self { actions, default, enabled, rule_id, pattern: None, conditions: Some(conditions) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PatternedPushRuleInit> for AnyPushRule {
|
||||||
|
fn from(init: PatternedPushRuleInit) -> Self {
|
||||||
|
let PatternedPushRuleInit { actions, default, enabled, rule_id, pattern } = init;
|
||||||
|
Self { actions, default, enabled, rule_id, pattern: Some(pattern), conditions: None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<AnyPushRule> for PushRule {
|
impl From<AnyPushRule> for PushRule {
|
||||||
fn from(push_rule: AnyPushRule) -> Self {
|
fn from(push_rule: AnyPushRule) -> Self {
|
||||||
let AnyPushRule { actions, default, enabled, rule_id, .. } = push_rule;
|
let AnyPushRule { actions, default, enabled, rule_id, .. } = push_rule;
|
||||||
@ -65,6 +92,7 @@ impl From<AnyPushRule> for PushRule {
|
|||||||
/// An error that happens when `AnyPushRule` cannot
|
/// An error that happens when `AnyPushRule` cannot
|
||||||
/// be converted into `PatternedPushRule`
|
/// be converted into `PatternedPushRule`
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct MissingPatternError;
|
pub struct MissingPatternError;
|
||||||
|
|
||||||
impl Display for MissingPatternError {
|
impl Display for MissingPatternError {
|
||||||
@ -92,6 +120,7 @@ impl TryFrom<AnyPushRule> for PatternedPushRule {
|
|||||||
/// An error that happens when `AnyPushRule` cannot
|
/// An error that happens when `AnyPushRule` cannot
|
||||||
/// be converted into `ConditionalPushRule`
|
/// be converted into `ConditionalPushRule`
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[non_exhaustive]
|
||||||
pub struct MissingConditionsError;
|
pub struct MissingConditionsError;
|
||||||
|
|
||||||
impl Display for MissingConditionsError {
|
impl Display for MissingConditionsError {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user