pub struct Message { /* private fields */ }
Expand description
A D-Bus message. A message contains headers - usually destination address, path, interface and member, and a list of arguments.
Implementations
sourceimpl Message
impl Message
sourcepub fn new_method_call<'d, 'p, 'i, 'm, D, P, I, M>(
destination: D,
path: P,
iface: I,
method: M
) -> Result<Message, String>where
D: Into<BusName<'d>>,
P: Into<Path<'p>>,
I: Into<Interface<'i>>,
M: Into<Member<'m>>,
pub fn new_method_call<'d, 'p, 'i, 'm, D, P, I, M>(
destination: D,
path: P,
iface: I,
method: M
) -> Result<Message, String>where
D: Into<BusName<'d>>,
P: Into<Path<'p>>,
I: Into<Interface<'i>>,
M: Into<Member<'m>>,
Creates a new method call message.
sourcepub fn method_call(
destination: &BusName<'_>,
path: &Path<'_>,
iface: &Interface<'_>,
name: &Member<'_>
) -> Message
pub fn method_call(
destination: &BusName<'_>,
path: &Path<'_>,
iface: &Interface<'_>,
name: &Member<'_>
) -> Message
Creates a new method call message.
sourcepub fn duplicate(&self) -> Result<Self, String>
pub fn duplicate(&self) -> Result<Self, String>
Creates a new message that is a replica of this message, but without a serial.
May fail if out of memory or file descriptors.
sourcepub fn call_with_args<'d, 'p, 'i, 'm, A, D, P, I, M>(
destination: D,
path: P,
iface: I,
method: M,
args: A
) -> Messagewhere
D: Into<BusName<'d>>,
P: Into<Path<'p>>,
I: Into<Interface<'i>>,
M: Into<Member<'m>>,
A: AppendAll,
pub fn call_with_args<'d, 'p, 'i, 'm, A, D, P, I, M>(
destination: D,
path: P,
iface: I,
method: M,
args: A
) -> Messagewhere
D: Into<BusName<'d>>,
P: Into<Path<'p>>,
I: Into<Interface<'i>>,
M: Into<Member<'m>>,
A: AppendAll,
Creates a new method call message.
sourcepub fn new_signal<P, I, M>(path: P, iface: I, name: M) -> Result<Message, String>where
P: Into<String>,
I: Into<String>,
M: Into<String>,
pub fn new_signal<P, I, M>(path: P, iface: I, name: M) -> Result<Message, String>where
P: Into<String>,
I: Into<String>,
M: Into<String>,
Creates a new signal message.
sourcepub fn signal(
path: &Path<'_>,
iface: &Interface<'_>,
name: &Member<'_>
) -> Message
pub fn signal(
path: &Path<'_>,
iface: &Interface<'_>,
name: &Member<'_>
) -> Message
Creates a new signal message.
sourcepub fn new_method_return(m: &Message) -> Option<Message>
pub fn new_method_return(m: &Message) -> Option<Message>
Creates a method reply for this method call.
sourcepub fn method_return(&self) -> Message
pub fn method_return(&self) -> Message
Creates a method return (reply) for this method call.
sourcepub fn return_with_args<A: AppendAll>(&self, args: A) -> Message
pub fn return_with_args<A: AppendAll>(&self, args: A) -> Message
Creates a reply for a method call message.
Panics if called for a message which is not a method call.
sourcepub fn error(&self, error_name: &ErrorName<'_>, error_message: &CStr) -> Message
pub fn error(&self, error_name: &ErrorName<'_>, error_message: &CStr) -> Message
Creates a new error reply
sourcepub fn get_items(&self) -> Vec<MessageItem>
pub fn get_items(&self) -> Vec<MessageItem>
Get the MessageItems that make up the message.
Note: use iter_init
or get1
/get2
/etc instead for faster access to the arguments.
This method is provided for backwards compatibility.
sourcepub fn get_serial(&self) -> Option<u32>
pub fn get_serial(&self) -> Option<u32>
Get the D-Bus serial of a message, if one was specified.
sourcepub fn get_reply_serial(&self) -> Option<u32>
pub fn get_reply_serial(&self) -> Option<u32>
Get the serial of the message this message is a reply to, if present.
sourcepub fn get_no_reply(&self) -> bool
pub fn get_no_reply(&self) -> bool
Returns true if the message does not expect a reply.
sourcepub fn set_no_reply(&mut self, v: bool)
pub fn set_no_reply(&mut self, v: bool)
Set whether or not the message expects a reply.
Set to true if you send a method call and do not want a reply.
sourcepub fn get_auto_start(&self) -> bool
pub fn get_auto_start(&self) -> bool
Returns true if the message can cause a service to be auto-started.
sourcepub fn set_auto_start(&mut self, v: bool)
pub fn set_auto_start(&mut self, v: bool)
Sets whether or not the message can cause a service to be auto-started.
Defaults to true.
sourcepub fn append_items(&mut self, v: &[MessageItem])
pub fn append_items(&mut self, v: &[MessageItem])
Add one or more MessageItems to this Message.
Note: using append1
, append2
or append3
might be faster, especially for large arrays.
This method is provided for backwards compatibility.
sourcepub fn append1<A: Append>(self, a: A) -> Self
pub fn append1<A: Append>(self, a: A) -> Self
Appends one argument to this message.
Use in builder style: e g m.method_return().append1(7i32)
sourcepub fn append2<A1: Append, A2: Append>(self, a1: A1, a2: A2) -> Self
pub fn append2<A1: Append, A2: Append>(self, a1: A1, a2: A2) -> Self
Appends two arguments to this message.
Use in builder style: e g m.method_return().append2(7i32, 6u8)
sourcepub fn append3<A1: Append, A2: Append, A3: Append>(
self,
a1: A1,
a2: A2,
a3: A3
) -> Self
pub fn append3<A1: Append, A2: Append, A3: Append>(
self,
a1: A1,
a2: A2,
a3: A3
) -> Self
Appends three arguments to this message.
Use in builder style: e g m.method_return().append3(7i32, 6u8, true)
sourcepub fn append_ref<A: RefArg>(self, r: &[A]) -> Self
pub fn append_ref<A: RefArg>(self, r: &[A]) -> Self
Appends RefArgs to this message.
Use in builder style: e g m.method_return().append_ref(&[7i32, 6u8, true])
sourcepub fn append_all<A: AppendAll>(&mut self, a: A)
pub fn append_all<A: AppendAll>(&mut self, a: A)
Appends arguments to a message.
sourcepub fn get1<'a, G1: Get<'a>>(&'a self) -> Option<G1>
pub fn get1<'a, G1: Get<'a>>(&'a self) -> Option<G1>
Gets the first argument from the message, if that argument is of type G1. Returns None if there are not enough arguments, or if types don’t match.
sourcepub fn get2<'a, G1: Get<'a>, G2: Get<'a>>(&'a self) -> (Option<G1>, Option<G2>)
pub fn get2<'a, G1: Get<'a>, G2: Get<'a>>(&'a self) -> (Option<G1>, Option<G2>)
Gets the first two arguments from the message, if those arguments are of type G1 and G2. Returns None if there are not enough arguments, or if types don’t match.
sourcepub fn get3<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>)
pub fn get3<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>)
Gets the first three arguments from the message, if those arguments are of type G1, G2 and G3. Returns None if there are not enough arguments, or if types don’t match.
sourcepub fn get4<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>, G4: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>, Option<G4>)
pub fn get4<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>, G4: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>, Option<G4>)
Gets the first four arguments from the message, if those arguments are of type G1, G2, G3 and G4. Returns None if there are not enough arguments, or if types don’t match.
sourcepub fn get5<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>, G4: Get<'a>, G5: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>, Option<G4>, Option<G5>)
pub fn get5<'a, G1: Get<'a>, G2: Get<'a>, G3: Get<'a>, G4: Get<'a>, G5: Get<'a>>(
&'a self
) -> (Option<G1>, Option<G2>, Option<G3>, Option<G4>, Option<G5>)
Gets the first five arguments from the message, if those arguments are of type G1, G2, G3 and G4.
Returns None if there are not enough arguments, or if types don’t match.
Note: If you need more than five arguments, use iter_init
instead.
sourcepub fn read1<'a, G1: Arg + Get<'a>>(&'a self) -> Result<G1, TypeMismatchError>
pub fn read1<'a, G1: Arg + Get<'a>>(&'a self) -> Result<G1, TypeMismatchError>
Gets the first argument from the message, if that argument is of type G1.
Returns a TypeMismatchError if there are not enough arguments, or if types don’t match.
sourcepub fn read2<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2), TypeMismatchError>
pub fn read2<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2), TypeMismatchError>
Gets the first two arguments from the message, if those arguments are of type G1 and G2.
Returns a TypeMismatchError if there are not enough arguments, or if types don’t match.
sourcepub fn read3<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3), TypeMismatchError>
pub fn read3<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3), TypeMismatchError>
Gets the first three arguments from the message, if those arguments are of type G1, G2 and G3.
Returns a TypeMismatchError if there are not enough arguments, or if types don’t match.
sourcepub fn read4<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>, G4: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3, G4), TypeMismatchError>
pub fn read4<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>, G4: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3, G4), TypeMismatchError>
Gets the first four arguments from the message, if those arguments are of type G1, G2, G3 and G4.
Returns a TypeMismatchError if there are not enough arguments, or if types don’t match.
sourcepub fn read5<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>, G4: Arg + Get<'a>, G5: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3, G4, G5), TypeMismatchError>
pub fn read5<'a, G1: Arg + Get<'a>, G2: Arg + Get<'a>, G3: Arg + Get<'a>, G4: Arg + Get<'a>, G5: Arg + Get<'a>>(
&'a self
) -> Result<(G1, G2, G3, G4, G5), TypeMismatchError>
Gets the first five arguments from the message, if those arguments are of type G1, G2, G3, G4 and G5.
Returns a TypeMismatchError if there are not enough arguments, or if types don’t match.
Note: If you need more than five arguments, use iter_init
instead.
sourcepub fn read_all<R: ReadAll>(&self) -> Result<R, Error>
pub fn read_all<R: ReadAll>(&self) -> Result<R, Error>
Gets arguments from a message.
If this was an error reply or if types mismatch, an error is returned.
sourcepub fn iter_init(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = Box<dyn RefArg + 'static>;
pub fn iter_init(&self) -> Iter<'_>ⓘNotable traits for Iter<'a>impl<'a> Iterator for Iter<'a> type Item = Box<dyn RefArg + 'static>;
Returns a struct for retreiving the arguments from a message. Supersedes get_items().
sourcepub fn msg_type(&self) -> MessageType
pub fn msg_type(&self) -> MessageType
Gets the MessageType of the Message.
sourcepub fn sender(&self) -> Option<BusName<'_>>
pub fn sender(&self) -> Option<BusName<'_>>
Gets the name of the connection that originated this message.
sourcepub fn destination(&self) -> Option<BusName<'_>>
pub fn destination(&self) -> Option<BusName<'_>>
Gets the destination this Message is being sent to.
sourcepub fn set_destination(&mut self, dest: Option<BusName<'_>>)
pub fn set_destination(&mut self, dest: Option<BusName<'_>>)
Sets the destination of this Message
If dest is none, that means broadcast to all relevant destinations.
sourcepub fn interface(&self) -> Option<Interface<'_>>
pub fn interface(&self) -> Option<Interface<'_>>
Gets the interface this Message is being sent to.
sourcepub fn as_result(&mut self) -> Result<&mut Message, Error>
pub fn as_result(&mut self) -> Result<&mut Message, Error>
When the remote end returns an error, the message itself is correct but its contents is an error. This method will transform such an error to a D-Bus Error or otherwise return the original message.
sourcepub fn set_serial(&mut self, val: u32)
pub fn set_serial(&mut self, val: u32)
Sets serial number manually - mostly for internal use
When sending a message, a serial will be automatically assigned, so you don’t need to call this method. However, it can be very useful in test code that is supposed to handle a method call. This way, you can create a method call and handle it without sending it to a real D-Bus instance.
sourcepub fn marshal<E, F: FnMut(&[u8]) -> Result<(), E>>(&self, f: F) -> Result<(), E>
pub fn marshal<E, F: FnMut(&[u8]) -> Result<(), E>>(&self, f: F) -> Result<(), E>
Marshals a message - mostly for internal use
The function f will be called one or more times with bytes to be written somewhere. You should call set_serial to manually set a serial number before calling this function