[][src]Module lv2rs_atom::tuple

Heterogenous array of sized and unsized atoms.

A tuple is a pretty simple collection of different atoms: It basically a chunk containing an arbitrary amount of atoms, aligned to 64-bit.

When initialized, a tuple does not contain any atoms. These have to be pushed to the tuple using the TupleWritingFrame trait. Every writing frame implements this trait via a blanket implementation and the trait is included in the crate's prelude. You can, therefore, act as if the extended methods were normal methods of a writing frame.

Reading atoms is done by iterating through all atoms one by one. Iterators are produced by the iter method.

An example:

extern crate lv2rs_atom as atom;
extern crate lv2rs_urid as urid;

use atom::prelude::*;
use atom::ports::*;
use urid::{CachedMap, debug::DebugMap};
use std::ffi::CStr;

pub struct Plugin {
    in_port: AtomInputPort<Tuple>,
    out_port: AtomOutputPort<Tuple>,
    urids: CachedMap,
}

impl Plugin {
    /// Simulated `run` method.
    fn run(&mut self) {
        // Writing
        {
            let mut frame =
                unsafe { self.out_port.write_atom_body(&(), &mut self.urids) }.unwrap();
            frame.push_atom::<i32>(&42, &mut self.urids).unwrap();
            frame.push_atom::<f32>(&17.0, &mut self.urids).unwrap();
        }

        let i32_urid = self.urids.map(<i32 as AtomBody>::get_uri());
        let f32_urid = self.urids.map(<f32 as AtomBody>::get_uri());

        // Reading.
        let tuple = unsafe { self.in_port.get_atom_body(&mut self.urids) }.unwrap();
        for sub_atom in tuple.iter() {
            match unsafe { sub_atom.get_body::<i32>(&mut self.urids) } {
                Ok(integer) => {
                    assert_eq!(42, *integer);
                    continue
                }
                Err(_) => (),
            }
            match unsafe { sub_atom.get_body::<f32>(&mut self.urids) } {
                Ok(float) => {
                    assert_eq!(17.0, *float);
                    continue
                }
                Err(_) => (),
            }
            panic!("Unknown property in object!");
        }
    }
}

// Getting a debug URID map.
let mut debug_map = DebugMap::new();
let mut urids = unsafe {debug_map.create_cached_map()};

// Creating the plugin.
let mut plugin = Plugin {
    in_port: AtomInputPort::new(),
    out_port: AtomOutputPort::new(),
    urids: urids,
};

// Creating the atom space.
let mut atom_space = vec![0u8; 256];
let atom = unsafe { (atom_space.as_mut_ptr() as *mut Atom).as_mut() }.unwrap();
*(atom.mut_size()) = 256 - 8;

// Connecting the ports.
plugin.in_port.connect_port(atom as &Atom);
plugin.out_port.connect_port(atom);

// Calling `run`.
plugin.run();

Traits

TupleWritingFrame

Extension for WritingFrame and WritingFrameExt for vectors.

Type Definitions

Tuple

Heterogenous array of sized and unsized atoms.