[−][src]Module lv2rs_atom::literal
UTF-8-encoded string.
This string atom corresponds to Rust's normal str
and String
types, since it is
UTF-8-encoded. A literal also contains, apart from the string, the URID of it's language.
When initialized, a literal does not contain any text. Every text has to be appended to the
literal using the LiteralWritingFrame
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.
You can aquire a literal's data using the lang
method
and the as_str
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<Literal>, out_port: AtomOutputPort<Literal>, urids: CachedMap, } impl Plugin { /// Simulated `run` method. fn run(&mut self) { // Writing { let mut frame = unsafe { self.out_port.write_atom_body(&0, &mut self.urids) }.unwrap(); frame.append_string("Hello World!"); } // Reading. let literal = unsafe { self.in_port.get_atom_body(&mut self.urids) }.unwrap(); let message = literal.as_str().unwrap(); assert_eq!("Hello World!", message); } } // 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();
Structs
LiteralHeader | The body header of a literal. |
Traits
LiteralWritingFrame | Extension for |
Type Definitions
Literal | UTF-8 encoded string. |