Device

Struct Device 

Source
pub struct Device<'a> { /* private fields */ }
Expand description

A device is libmapper’s connection to the distributed graph. Each device is a collection of signal instances and their metadata.

§Examples

use libmapper_rs::device::Device;
use std::time::Duration;
// you can create a device with Device::create
let dev = Device::create("rust");
// you have to poll a device occasionally to make things happen
loop {
    dev.poll_and_block(Duration::from_millis(10)); // poll in 10ms intervals
    if dev.is_ready() {
       break;
    }
}
// create signals, etc...

Implementations§

Source§

impl Device<'_>

Source

pub fn create(name: &str) -> Device<'_>

Create a new device with the given name. The device will use it’s own connection to the graph.

Before calling any other methods on the device, you should poll it until it is ready.

§Notes

If you plan on creating multiple devices, consider using (Device::create_from_graph)Device::create_from_graph instead to pool resources.

Source

pub fn create_from_graph<'a>(name: &str, graph: &'a Graph) -> Device<'a>

Create a new device with a shared graph. Sharing a graph between devices allows them to pool some resources and networking, potentially improving performance.

Source§

impl Device<'_>

Source

pub fn poll(&self)

Poll the device without blocking

§Notes

You may want to use poll_all in a multithreaded enviroment, when using non-blocking polling libmapper will use a heuristic to determine how many messages to parse at once for performance. If you don’t care how long this function will take to run, call Device::poll_all.

Source

pub fn poll_all(&self)

Processes all messages in the device’s queue, no matter how long it takes. If using dedicated threads to poll devices this is probably what you want to use instead of poll

Source

pub fn poll_and_block(&self, time: Duration)

Blocks the current thread for a specified amount of time. Use this function instead of sleeping in a loop.

Source§

impl Device<'_>

Source

pub fn is_ready(&self) -> bool

Tests if the device is ready to use. Do not try to call any other methods until this returns true.

Source§

impl<'a> Device<'a>

Source

pub fn get_graph(&self) -> Option<&'a Graph>

Get the shared graph used by this device. If the device was created with Device::create this will return None.

Source§

impl Device<'_>

Source

pub fn has_shared_graph(&self) -> bool

Check if the device was created with a shared graph.

Source

pub fn create_signal<T: MappableType + Copy>( &self, name: &str, direction: mpr_dir, ) -> Signal

Create a signal with the given name and direction.

§Notes
  • The signal will have a vector length of 1 (i.e. single value).
  • The passed generic parameter controls what type of data the signal will hold.
§Examples
use libmapper_rs::device::Device;
use libmapper_rs::constants::mpr_dir;
fn setup_signals(dev: &Device) {
    // create an outgoing signal that outputs a single f64 value
    let sig = dev.create_signal::<f64>("test_signal", mpr_dir::MPR_DIR_OUT);
}
Source

pub fn create_vector_signal<T: MappableType + Copy>( &self, name: &str, direction: mpr_dir, vector_length: u32, ) -> Signal

Create a signal with the given name, direction, and vector length.

§Notes
  • The passed generic parameter controls what type of data the signal will hold.
Source

pub fn get_signals(&self, direction: mpr_dir) -> Vec<Signal>

Get a list of all signals owned by this device.

Trait Implementations§

Source§

impl AsMprObject for Device<'_>

Source§

impl Drop for Device<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Device<'_>

Source§

impl Sync for Device<'_>

Auto Trait Implementations§

§

impl<'a> Freeze for Device<'a>

§

impl<'a> RefUnwindSafe for Device<'a>

§

impl<'a> Unpin for Device<'a>

§

impl<'a> UnwindSafe for Device<'a>

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<A> MapperObject for A
where A: AsMprObject,

Source§

fn get_type(&self) -> mpr_type

Get the mpr_type representing this object
Source§

fn set_property<T>(&self, property: mpr_prop, value: T)
where T: MappableType,

Set a property on this object to a numerical value
Source§

fn set_property_str(&self, property: mpr_prop, value: &str)

Set a property on this object to a string value
Source§

fn get_property<T>(&self, property: mpr_prop) -> Result<T, PropertyError>
where T: MappableType + Copy,

Get the value of a property by it’s key from this object. If the property does not exist, or if the type is not matched, this function will return an error.
Source§

fn get_property_str(&self, property: mpr_prop) -> Result<String, PropertyError>

Get the value of a string property by it’s key from this object. If the property does not exist, or if the type is not matched, this function will return an error.
Source§

fn set_custom_property<T>(&self, property: &str, value: T, publish: bool)
where T: MappableType,

Set a user-defined property to the specified value. The property is identified by a unique, case-sensitive string key. 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.