ev3dev_lang_rust/
device.rs

1use crate::{Attribute, Ev3Result};
2
3/// The ev3dev device base trait
4pub trait Device {
5    /// Returns the attribute wrapper for an attribute name.
6    fn get_attribute(&self, name: &str) -> Attribute;
7
8    /// Returns the name of the port that the motor is connected to.
9    fn get_address(&self) -> Ev3Result<String> {
10        self.get_attribute("address").get()
11    }
12
13    /// Sends a command to the device controller.
14    fn set_command(&self, command: &str) -> Ev3Result<()> {
15        self.get_attribute("command").set_str_slice(command)
16    }
17
18    /// Returns a space separated list of commands that are supported by the device controller.
19    fn get_commands(&self) -> Ev3Result<Vec<String>> {
20        self.get_attribute("commands").get_vec()
21    }
22
23    /// Returns the name of the driver that provides this device.
24    fn get_driver_name(&self) -> Ev3Result<String> {
25        self.get_attribute("driver_name").get()
26    }
27}