Struct zbus::MatchRule

source ·
pub struct MatchRule<'m> { /* private fields */ }
Expand description

A bus match rule for subscribing to specific messages.

This is mainly used by peer to subscribe to specific signals as by default the bus will not send out most broadcasted signals. This API is intended to make it easy to create and parse match rules. See the match rules section of the D-Bus specification for a description of each possible element of a match rule.

§Examples

use std::convert::TryFrom;

// Let's take the most typical example of match rule to subscribe to properties' changes:
let rule = MatchRule::builder()
    .msg_type(zbus::MessageType::Signal)
    .sender("org.freedesktop.DBus")?
    .interface("org.freedesktop.DBus.Properties")?
    .member("PropertiesChanged")?
    .add_arg("org.zbus")?
    // Sometimes it's useful to match empty strings (null check).
    .add_arg("")?
    .build();
let rule_str = rule.to_string();
assert_eq!(
    rule_str,
    "type='signal',\
     sender='org.freedesktop.DBus',\
     interface='org.freedesktop.DBus.Properties',\
     member='PropertiesChanged',\
     arg0='org.zbus',\
     arg1=''",
);

// Let's parse it back.
let parsed_rule = MatchRule::try_from(rule_str.as_str())?;
assert_eq!(rule, parsed_rule);

// Now for `ObjectManager::InterfacesAdded` signal.
let rule = MatchRule::builder()
    .msg_type(zbus::MessageType::Signal)
    .sender("org.zbus")?
    .interface("org.freedesktop.DBus.ObjectManager")?
    .member("InterfacesAdded")?
    .arg_path(0, "/org/zbus/NewPath")?
    .build();
let rule_str = rule.to_string();
assert_eq!(
    rule_str,
    "type='signal',\
     sender='org.zbus',\
     interface='org.freedesktop.DBus.ObjectManager',\
     member='InterfacesAdded',\
     arg0path='/org/zbus/NewPath'",
);

// Let's parse it back.
let parsed_rule = MatchRule::try_from(rule_str.as_str())?;
assert_eq!(rule, parsed_rule);

§Caveats

The PartialEq implementation assumes arguments in both rules are in the same order.

Implementations§

source§

impl<'m> MatchRule<'m>

source

pub fn builder() -> MatchRuleBuilder<'m>

Create a builder for MatchRuleBuilder.

source

pub fn sender(&self) -> Option<&BusName<'_>>

The sender, if set.

source

pub fn msg_type(&self) -> Option<MessageType>

The message type, if set.

source

pub fn interface(&self) -> Option<&InterfaceName<'_>>

The interfac, if set.

source

pub fn member(&self) -> Option<&MemberName<'_>>

The member name if set.

source

pub fn path_spec(&self) -> Option<&MatchRulePathSpec<'_>>

The path or path namespace, if set.

source

pub fn destination(&self) -> Option<&UniqueName<'_>>

The destination, if set.

source

pub fn args(&self) -> &[(u8, Str<'_>)]

The arguments.

source

pub fn arg_paths(&self) -> &[(u8, ObjectPath<'_>)]

The argument paths.

source

pub fn arg0namespace(&self) -> Option<&InterfaceName<'_>>

👎Deprecated: use arg0ns instead

Match messages whose first argument is within the specified namespace.

This function is deprecated because the choice of InterfaceName was too restrictive.

source

pub fn arg0ns(&self) -> Option<&Str<'m>>

Match messages whose first argument is within the specified namespace.

source

pub fn to_owned(&self) -> MatchRule<'static>

Creates an owned clone of self.

source

pub fn into_owned(self) -> MatchRule<'static>

Creates an owned clone of self.

source

pub fn matches(&self, msg: &Message) -> Result<bool>

Match the given message against this rule.

§Caveats

Since this method doesn’t have any knowledge of names on the bus (or even connection to a bus) matching always succeeds for:

  • sender in the rule (if set) that is a well-known name. The sender on a message is always a unique name.
  • destination in the rule when destination on the msg is a well-known name. The destination on match rule is always a unique name.

Trait Implementations§

source§

impl<'m> Clone for MatchRule<'m>

source§

fn clone(&self) -> MatchRule<'m>

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<'m> Debug for MatchRule<'m>

source§

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

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

impl<'de: 'm, 'm> Deserialize<'de> for MatchRule<'m>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

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

impl Display for MatchRule<'_>

source§

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

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

impl<'unowned, 'owned: 'unowned> From<&'owned OwnedMatchRule> for MatchRule<'unowned>

source§

fn from(rule: &'owned OwnedMatchRule) -> Self

Converts to this type from the input type.
source§

impl From<MatchRule<'_>> for OwnedMatchRule

source§

fn from(rule: MatchRule<'_>) -> Self

Converts to this type from the input type.
source§

impl From<OwnedMatchRule> for MatchRule<'static>

source§

fn from(o: OwnedMatchRule) -> Self

Converts to this type from the input type.
source§

impl<'m> Hash for MatchRule<'m>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<MatchRule<'_>> for OwnedMatchRule

source§

fn eq(&self, other: &MatchRule<'_>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'m> PartialEq for MatchRule<'m>

source§

fn eq(&self, other: &MatchRule<'m>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for MatchRule<'_>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'m> TryFrom<&'m str> for MatchRule<'m>

source§

type Error = Error

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

fn try_from(s: &'m str) -> Result<Self>

Performs the conversion.
source§

impl<'m> Type for MatchRule<'m>

source§

fn signature() -> Signature<'static>

Get the signature for the implementing type. Read more
source§

impl<'m> Eq for MatchRule<'m>

source§

impl<'m> StructuralPartialEq for MatchRule<'m>

Auto Trait Implementations§

§

impl<'m> Freeze for MatchRule<'m>

§

impl<'m> RefUnwindSafe for MatchRule<'m>

§

impl<'m> Send for MatchRule<'m>

§

impl<'m> Sync for MatchRule<'m>

§

impl<'m> Unpin for MatchRule<'m>

§

impl<'m> UnwindSafe for MatchRule<'m>

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 T)

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

impl<'de, T> DynamicDeserialize<'de> for T
where T: Type + Deserialize<'de> + ?Sized,

source§

type Deserializer = PhantomData<T>

A DeserializeSeed implementation for this type.
source§

fn deserializer_for_signature<S>( signature: S, ) -> Result<<T as DynamicDeserialize<'de>>::Deserializer, Error>
where S: TryInto<Signature<'de>>, <S as TryInto<Signature<'de>>>::Error: Into<Error>,

Get a deserializer compatible with this signature.
source§

impl<T> DynamicType for T
where T: Type + ?Sized,

source§

fn dynamic_signature(&self) -> Signature<'_>

Get the signature for the implementing type. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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>,