Struct ev3dev_lang_rust::Attribute[][src]

pub struct Attribute { /* fields omitted */ }
Expand description

A wrapper to a attribute file in the /sys/class/ directory.

Implementations

Create a new Attribute instance for the given path.

Create a new Attribute instance that wrappes the file /sys/class/{class_name}/{name}{attribute_name}.

Create a new Attribute instance by a discriminator attribute. This can be used to manually access driver files or advances features like raw encoder values. To find the correct file, this function iterates over all directories $d in root_path and checks if the content of root_path/$d/discriminator_path equals discriminator_value. When a match is found it returns an Attribute for file root_path/$d/attribute_path.

Example
use ev3dev_lang_rust::Attribute;

// Get value0 of first connected color sensor.
let color_sensor_value = Attribute::from_path_with_discriminator(
    "/sys/class/lego-sensor",
    "value0",
    "driver_name",
    "lego-ev3-color"
)?;
println!("value0 of color sensor: {}", color_sensor_value.get::<i32>()?);

// Get raw rotation count of motor in port `A`.
// See https://github.com/ev3dev/ev3dev/wiki/Internals:-ev3dev-stretch for more infomation.
let rotation_count = Attribute::from_path_with_discriminator(
    "/sys/bus/iio/devices",
    "in_count0_raw",
    "name",
    "ev3-tacho"
)?;
println!("Raw rotation count: {}", rotation_count.get::<i32>()?);

Returns the current value of the wrapped file. The value is parsed to the type T. Returns a Ev3Result::InternalError if the current value is not parsable to type T.

Sets the value of the wrapped file. The value is parsed from the type T. Returns a Ev3Result::InternalError if the file is not writable.

Sets the value of the wrapped file. This function skips the string parsing of the self.set<T>() function. Returns a Ev3Result::InternalError if the file is not writable.

Returns a string vector representation of the wrapped file. The file value is splitet at whitespaces.

Returns a C pointer to the wrapped file.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.