Struct MethodErr

Source
pub struct MethodErr(/* private fields */);
Expand description

A D-Bus Method Error, containing an error name and a description.

Unlike the “Error” struct, this is a Rust native struct.

Implementations§

Source§

impl MethodErr

Source

pub fn invalid_arg<T>(a: &T) -> MethodErr
where T: Debug + ?Sized,

Create an Invalid Args MethodErr.

Source

pub fn no_arg() -> MethodErr

Create a MethodErr that there are not enough arguments given.

Source

pub fn failed<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the method failed in the way specified.

Examples found in repository?
examples/adv_server.rs (line 75)
57fn create_iface(check_complete_s: mpsc::Sender<i32>) -> (Interface<MTFn<TData>, TData>, Arc<Signal<TData>>) {
58    let f = tree::Factory::new_fn();
59
60    let check_complete = Arc::new(f.signal("CheckComplete", ()));
61
62    (f.interface("com.example.dbus.rs.device", ())
63        // The online property can be both set and get
64        .add_p(f.property::<bool,_>("online", ())
65            .access(Access::ReadWrite)
66            .on_get(|i, m| {
67                let dev: &Arc<Device> = m.path.get_data();
68                i.append(dev.online.get());
69                Ok(())
70            })
71            .on_set(|i, m| {
72                let dev: &Arc<Device> = m.path.get_data();
73                let b: bool = i.read()?;
74                if b && dev.checking.get() {
75                    return Err(MethodErr::failed(&"Device currently under check, cannot bring online"))
76                }
77                dev.online.set(b);
78                Ok(())
79            })
80        )
81        // The "checking" property is read only
82        .add_p(f.property::<bool,_>("checking", ())
83            .emits_changed(EmitsChangedSignal::False)
84            .on_get(|i, m| {
85                let dev: &Arc<Device> = m.path.get_data();
86                i.append(dev.checking.get());
87                Ok(())
88            })
89        )
90        // ...and so is the "description" property
91        .add_p(f.property::<&str,_>("description", ())
92            .emits_changed(EmitsChangedSignal::Const)
93            .on_get(|i, m| {
94                let dev: &Arc<Device> = m.path.get_data();
95                i.append(&dev.description);
96                Ok(())
97            })
98        )
99        // ...add a method for starting a device check...
100        .add_m(f.method("check", (), move |m| {
101            let dev: &Arc<Device> = m.path.get_data();
102            if dev.checking.get() {
103                return Err(MethodErr::failed(&"Device currently under check, cannot start another check"))
104            }
105            if dev.online.get() {
106                return Err(MethodErr::failed(&"Device is currently online, cannot start check"))
107            }
108            dev.checking.set(true);
109
110            // Start some lengthy processing in a separate thread...
111            let devindex = dev.index;
112            let ch = check_complete_s.clone();
113            thread::spawn(move || {
114
115                // Bogus check of device
116                use std::time::Duration;
117                thread::sleep(Duration::from_secs(15));
118
119                // Tell main thread that we finished
120                ch.send(devindex).unwrap();
121            });
122            Ok(vec!(m.msg.method_return()))
123        }))
124        // Indicate that we send a special signal once checking has completed.
125        .add_s(check_complete.clone())
126    , check_complete)
127}
Source

pub fn no_path<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the Object path was unknown.

Source

pub fn no_interface<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the Interface was unknown.

Source

pub fn no_method<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the Method was unknown.

Source

pub fn no_property<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the Property was unknown.

Source

pub fn ro_property<T>(a: &T) -> MethodErr
where T: Display + ?Sized,

Create a MethodErr that the Property was read-only.

Source

pub fn errorname(&self) -> &ErrorName<'static>

Error name accessor

Source

pub fn description(&self) -> &str

Description accessor

Source

pub fn to_message(&self, msg: &Message) -> Message

Creates an error reply from a method call message.

Note: You normally don’t need to use this function, as it is called internally from Tree::handle.

Trait Implementations§

Source§

impl Clone for MethodErr

Source§

fn clone(&self) -> MethodErr

Returns a duplicate 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 MethodErr

Source§

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

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

impl Display for MethodErr

Source§

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

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

impl Error for MethodErr

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<T, M> From<(T, M)> for MethodErr
where T: Into<ErrorName<'static>>, M: Into<String>,

Source§

fn from(_: (T, M)) -> MethodErr

Converts to this type from the input type.
Source§

impl From<Error> for MethodErr

Source§

fn from(t: Error) -> MethodErr

Converts to this type from the input type.
Source§

impl From<TypeMismatchError> for MethodErr

Source§

fn from(t: TypeMismatchError) -> MethodErr

Converts to this type from the input type.
Source§

impl Ord for MethodErr

Source§

fn cmp(&self, other: &MethodErr) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for MethodErr

Source§

fn eq(&self, other: &MethodErr) -> 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 PartialOrd for MethodErr

Source§

fn partial_cmp(&self, other: &MethodErr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for MethodErr

Source§

impl StructuralPartialEq for MethodErr

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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§

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.