Skip to main content

iri_s/iri/
mod.rs

1mod iri_or_string;
2mod iris;
3#[cfg(not(target_family = "wasm"))]
4mod test;
5mod visitor;
6#[cfg(target_family = "wasm")]
7mod wasm_stubs;
8
9pub use iri_or_string::Iri;
10pub use iris::IriS;
11
12/// Generates an [`IriS`] from a string literal.
13/// ```
14///
15/// #[macro_use]
16/// # use iri_s::{IriS, iri};
17///
18/// let iri = iri!("https://example.org/");
19///
20/// assert_eq!(iri.as_str(), "https://example.org/");
21/// ```
22///
23/// At this moment the implementation leverages on [`oxrdf::NamedNode`](https://docs.rs/oxrdf/latest/oxrdf/struct.NamedNode.html)
24///
25/// Example
26///
27/// ```
28/// # use iri_s::IriS;
29/// # use std::str::FromStr;
30///
31/// let iri = IriS::from_str("https://example.org/").unwrap();
32///
33/// assert_eq!(iri.as_str(), "https://example.org/")
34/// ```
35///
36#[macro_export]
37macro_rules! iri {
38    ($lit: tt) => {
39        $crate::IriS::new_unchecked($lit)
40    };
41}
42
43/// This macro creates a static variable that is initialized once andm can be accessed globally.
44// TODO - This should be in a general utilities crate or even removed since is not used currently
45#[macro_export]
46macro_rules! static_once {
47    ($name:ident, $type:ty, $init:expr) => {
48        pub fn $name() -> &'static $type {
49            static ONCE: std::sync::OnceLock<$type> = std::sync::OnceLock::new();
50            ONCE.get_or_init(|| $init)
51        }
52    };
53}
54
55/// This macro creates a static [`IriS`] variable that is initialized once and can be accessed globally.
56#[macro_export]
57macro_rules! iri_once {
58    ($name:ident, $str:expr) => {
59        pub fn $name() -> &'static IriS {
60            static ONCE: std::sync::OnceLock<IriS> = std::sync::OnceLock::new();
61            ONCE.get_or_init(|| IriS::new_unchecked($str))
62        }
63    };
64}