Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

Context is the struct that accompanies you through your method call handler, providing helpful information about the message sent from the client, as well as some methods to send extra messages (typically signals) in return.

Implementations§

Source§

impl Context

Source

pub fn new(msg: Message) -> Option<Self>

Creates a new Context.

Usually you’re not creating your own context, as the crossroads instance is creating one for you.

Source

pub fn check<R, F: FnOnce(&mut Context) -> Result<R, MethodErr>>( &mut self, f: F, ) -> Result<R, ()>

Convenience method that sets an error reply if the closure returns an error.

Source

pub fn do_reply<F: FnOnce(&mut Message)>(&mut self, f: F)

If the reply is not already set, creates a new method return message and calls the closure so that the closure can fill in the arguments.

Source

pub fn reply<OA: AppendAll>( &mut self, result: Result<OA, MethodErr>, ) -> PhantomData<OA>

Replies to the incoming message, if the reply is not already set. This is what you’ll normally have last in your async method.

Returns PhantomData just to aid the type system.

Source

pub fn set_reply( &mut self, msg: Option<Message>, check_no_reply: bool, check_set: bool, )

Low-level function to set a reply

You should probably prefer do_reply, or reply_ok / reply_err for async methods.

Source

pub fn flush_messages<S: Sender + ?Sized>(&mut self, conn: &S) -> Result<(), ()>

Low-level function to flush set messages

This is called internally, you should probably not use it.

Source

pub fn make_signal<'b, A, N>(&self, name: N, args: A) -> Message
where A: AppendAll, N: Into<Member<'b>>,

Makes a new signal with the current interface and path

Source

pub fn push_msg(&mut self, msg: Message)

Adds an extra message to send together with the message reply, e g, a custom signal.

Source

pub fn path(&self) -> &Path<'static>

The current object path.

Source

pub fn interface(&self) -> Option<&Interface<'static>>

The current interface name.

The D-Bus specfication allows for the interface to be unspecified, hence this returns an option. This is very rarely used in practice.

Source

pub fn method(&self) -> &Member<'static>

The current method name.

Source

pub fn message(&self) -> &Message

The message that caused this method to be called.

Source

pub fn has_reply(&self) -> bool

True if a reply (error or method return) has been set.

Source

pub fn has_error(&self) -> bool

Returns true is “reply_err” has been called, or “check” ever returned an error

Trait Implementations§

Source§

impl Debug for Context

Source§

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

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

impl Drop for Context

Source§

fn drop(&mut self)

Executes the destructor for this type. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.