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
impl MethodErr
Sourcepub fn invalid_arg<T>(a: &T) -> MethodErr
pub fn invalid_arg<T>(a: &T) -> MethodErr
Create an Invalid Args MethodErr.
Sourcepub fn failed<T>(a: &T) -> MethodErr
pub fn failed<T>(a: &T) -> MethodErr
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}
Sourcepub fn no_interface<T>(a: &T) -> MethodErr
pub fn no_interface<T>(a: &T) -> MethodErr
Create a MethodErr that the Interface was unknown.
Sourcepub fn no_property<T>(a: &T) -> MethodErr
pub fn no_property<T>(a: &T) -> MethodErr
Create a MethodErr that the Property was unknown.
Sourcepub fn ro_property<T>(a: &T) -> MethodErr
pub fn ro_property<T>(a: &T) -> MethodErr
Create a MethodErr that the Property was read-only.
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
Description accessor
Sourcepub fn to_message(&self, msg: &Message) -> Message
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 Error for MethodErr
impl Error for MethodErr
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<TypeMismatchError> for MethodErr
impl From<TypeMismatchError> for MethodErr
Source§fn from(t: TypeMismatchError) -> MethodErr
fn from(t: TypeMismatchError) -> MethodErr
Converts to this type from the input type.
Source§impl Ord for MethodErr
impl Ord for MethodErr
Source§impl PartialOrd for MethodErr
impl PartialOrd for MethodErr
impl Eq for MethodErr
impl StructuralPartialEq for MethodErr
Auto Trait Implementations§
impl Freeze for MethodErr
impl RefUnwindSafe for MethodErr
impl Send for MethodErr
impl Sync for MethodErr
impl Unpin for MethodErr
impl UnwindSafe for MethodErr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more