Macro rdftk_names::namespace[][src]

macro_rules! namespace {
    ($prefix:expr, $namespace:expr, { $($fn_name:ident, $name:expr),* }) => { ... };
}
Expand description

This macro produces the constants and functions to describe a vocabulary. It creates the following items.

  1. An identifier for the vocabulary struct.
  2. A constant, PREFIX that contains the string passed in the $prefix parameter.
  3. A constant, NAMESPACE that contains the string passed in the namespace parameter.
  4. For each pair of $fn_name, $name (assuming foo and "Foo"):
    1. create a function fn foo() -> IRI that returns the name as a full IRI. This concatenates NAMESPACE and $name.
    2. create a function fn foo_qname() -> String that returns a qualified name String. This concatenates the PREFIX, ":", and $name.

Example

Given the following namespace invocation,

#[macro_use]
extern crate rdftk_names;

namespace!(FooBarVocab, "fb", "http://example.com/schema/FooBar#", { foo, "Foo" } );

The following would be generated.

use rdftk_iri::IRI;
use std::str::FromStr;

pub struct FooBarVocab { ... }

impl Default for FooBarVocab { ... }

impl Vocabulary for FooBarVocab { ... }

impl FooBarVocab {
    pub fn foo(&self) -> &Arc<IRI> { ... }
    pub foo_qname(&self) -> &String { ... }
}