[][src]Crate lv2rs_urid

A Rust re-implementation of the LV2 URID library.

This LV2 feature enables you to map URIs to numbers and reverse.

Use

URID mapping is only possible in the instantiate function of a plugin since there is no guarantee that the required pointers live longer than the instantiate function call. Here is an example:

// import the required crates.
extern crate lv2rs_core as core;
extern crate lv2rs_urid as urid;
use std::ffi::CStr;
 
// A dummy plugin that doesn't actually do anything.
struct UridPlugin {}

impl core::Plugin for UridPlugin {
    fn instantiate(
        descriptor: &core::Descriptor,
        rate: f64,
        bundle_path: &CStr,
        features: Option<&[*mut core::Feature]>
    ) -> Option<Self> where Self: Sized {

        // First, we have to create a Hashmap from the features, since this speeds up the
        // feature detection.
        // If there are no features, we return None.
        let features = match features {
            Some(features) => unsafe {core::Feature::map_features(features)},
            None => return None,
        };

        // Try to get the mapper and the un-mapper from the features map.
        // Here, we simply unwrap the results for simplicity, but you should properly check
        // them in production code.
        let map = urid::Map::try_from_features(&features).unwrap();
        let unmap = urid::Unmap::try_from_features(&features).unwrap();

        // Create a URI, map it, and un-map it.
        let github_uri = CStr::from_bytes_with_nul(b"https://github.com\0").unwrap();
        let github_urid = map.map(github_uri);
        let github_uri = unmap.unmap(github_urid);

        Some(Self {})
    }

    // Blank implementations to keep the compiler quiet.
    unsafe fn connect_port(&mut self, _port: u32, _data: *mut ()) {}
    fn run(&mut self, _n_samples: u32) {}
}

Modules

uris

Structs

CachedMap

Cached version of Map

CachedUnmap

Cached version of Unmap

Map

Struct for mapping URIs to URIDs.

Unmap

Struct for mapping URIDs to URIs.

Type Definitions

MapHandle

Type to describe pointers to map handles.

URID

Type for describing URIDs.

UnmapHandle

Type to describe pointers to unmap handles.