ruma::push

Struct Ruleset

Source
#[non_exhaustive]
pub struct Ruleset { pub content: IndexSet<PatternedPushRule>, pub override_: IndexSet<ConditionalPushRule>, pub room: IndexSet<SimplePushRule<OwnedRoomId>>, pub sender: IndexSet<SimplePushRule<OwnedUserId>>, pub underride: IndexSet<ConditionalPushRule>, }
Expand description

A push ruleset scopes a set of rules according to some criteria.

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.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§content: IndexSet<PatternedPushRule>

These rules configure behavior for (unencrypted) messages that match certain patterns.

§override_: IndexSet<ConditionalPushRule>

These user-configured rules are given the highest priority.

This field is named override_ instead of override because the latter is a reserved keyword in Rust.

§room: IndexSet<SimplePushRule<OwnedRoomId>>

These rules change the behavior of all messages for a given room.

§sender: IndexSet<SimplePushRule<OwnedUserId>>

These rules configure notification behavior for messages from a specific Matrix user ID.

§underride: IndexSet<ConditionalPushRule>

These rules are identical to override rules, but have a lower priority than content, room and sender rules.

Implementations§

Source§

impl Ruleset

Source

pub fn server_default(user_id: &UserId) -> Ruleset

Available on crate feature events only.

The list of all predefined push rules.

§Parameters
  • user_id: the user for which to generate the default rules. Some rules depend on the user’s ID (for instance those to send notifications when they are mentioned).
Source

pub fn update_with_server_default(&mut self, new_server_default: Ruleset)

Available on crate feature events only.

Update this ruleset with the given server-default push rules.

This will replace the server-default rules in this ruleset (with default set to true) with the given ones while keeping the enabled and actions fields in the same state.

The default rules in this ruleset that are not in the new server-default rules are removed.

§Parameters
  • server_default: the new server-default push rules. This ruleset must not contain non-default rules.
Source§

impl Ruleset

Source

pub fn new() -> Ruleset

Available on crate feature events only.

Creates an empty Ruleset.

Source

pub fn iter(&self) -> RulesetIter<'_>

Available on crate feature events only.

Creates a borrowing iterator over all push rules in this Ruleset.

For an owning iterator, use .into_iter().

Source

pub fn insert( &mut self, rule: NewPushRule, after: Option<&str>, before: Option<&str>, ) -> Result<(), InsertPushRuleError>

Available on crate feature events only.

Inserts a user-defined rule in the rule set.

If a rule with the same kind and rule_id exists, it will be replaced.

If after or before is set, the rule will be moved relative to the rule with the given ID. If both are set, the rule will become the next-most important rule with respect to before. If neither are set, and the rule is newly inserted, it will become the rule with the highest priority of its kind.

Returns an error if the parameters are invalid.

Source

pub fn get( &self, kind: RuleKind, rule_id: impl AsRef<str>, ) -> Option<AnyPushRuleRef<'_>>

Available on crate feature events only.

Get the rule from the given kind and with the given rule_id in the rule set.

Source

pub fn set_enabled( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, enabled: bool, ) -> Result<(), RuleNotFoundError>

Available on crate feature events only.

Set whether the rule from the given kind and with the given rule_id in the rule set is enabled.

Returns an error if the rule can’t be found.

Source

pub fn set_actions( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, actions: Vec<Action>, ) -> Result<(), RuleNotFoundError>

Available on crate feature events only.

Set the actions of the rule from the given kind and with the given rule_id in the rule set.

Returns an error if the rule can’t be found.

Source

pub fn get_match<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> Option<AnyPushRuleRef<'_>>

Available on crate feature events only.

Get the first push rule that applies to this event, if any.

§Arguments
  • event - The raw JSON of a room message event.
  • context - The context of the message and room at the time of the event.
Source

pub fn get_actions<T>( &self, event: &Raw<T>, context: &PushConditionRoomCtx, ) -> &[Action]

Available on crate feature events only.

Get the push actions that apply to this event.

Returns an empty slice if no push rule applies.

§Arguments
  • event - The raw JSON of a room message event.
  • context - The context of the message and room at the time of the event.
Source

pub fn remove( &mut self, kind: RuleKind, rule_id: impl AsRef<str>, ) -> Result<(), RemovePushRuleError>

Available on crate feature events only.

Removes a user-defined rule in the rule set.

Returns an error if the parameters are invalid.

Trait Implementations§

Source§

impl Clone for Ruleset

Source§

fn clone(&self) -> Ruleset

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ruleset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for Ruleset

Source§

fn default() -> Ruleset

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Ruleset

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Ruleset, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Ruleset> for PushRulesEventContent

Source§

fn from(global: Ruleset) -> PushRulesEventContent

Converts to this type from the input type.
Source§

impl<'a> IntoIterator for &'a Ruleset

Source§

type Item = AnyPushRuleRef<'a>

The type of the elements being iterated over.
Source§

type IntoIter = RulesetIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Ruleset as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for Ruleset

Source§

type Item = AnyPushRule

The type of the elements being iterated over.
Source§

type IntoIter = RulesetIntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Ruleset as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl Serialize for Ruleset

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T