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.
- An identifier for the vocabulary struct.
- A constant,
PREFIX
that contains the string passed in the$prefix
parameter. - A constant,
NAMESPACE
that contains the string passed in thenamespace
parameter. - For each pair of
$fn_name
,$name
(assumingfoo
and"Foo"
):- create a function
fn foo() -> IRI
that returns the name as a full IRI. This concatenatesNAMESPACE
and$name
. - create a function
fn foo_qname() -> String
that returns a qualified name String. This concatenates thePREFIX
,":"
, and$name
.
- create a function
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 { ... } }