parent
2ac7a1b1de
commit
23e11fabe6
1 changed files with 19 additions and 0 deletions
19
src/lib.rs
19
src/lib.rs
|
@ -51,6 +51,16 @@ pub use mentat_db::{
|
|||
new_connection,
|
||||
};
|
||||
|
||||
/// Produce the appropriate `Variable` for the provided valid ?-prefixed name.
|
||||
/// This lives here because we can't re-export macros:
|
||||
/// https://github.com/rust-lang/rust/issues/29638.
|
||||
#[macro_export]
|
||||
macro_rules! var {
|
||||
( ? $var:ident ) => {
|
||||
$crate::Variable::from_valid_name(concat!("?", stringify!($var)))
|
||||
};
|
||||
}
|
||||
|
||||
/// Produce the appropriate `NamespacedKeyword` for the provided namespace and name.
|
||||
/// This lives here because we can't re-export macros:
|
||||
/// https://github.com/rust-lang/rust/issues/29638.
|
||||
|
@ -121,4 +131,13 @@ mod tests {
|
|||
assert_eq!(kw!(:foo/bar), NamespacedKeyword::new("foo", "bar"));
|
||||
assert_eq!(kw!(:org.mozilla.foo/bar_baz), NamespacedKeyword::new("org.mozilla.foo", "bar_baz"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_var() {
|
||||
let foo_baz = var!(?foo_baz);
|
||||
let vu = var!(?vü);
|
||||
assert_eq!(foo_baz, Variable::from_valid_name("?foo_baz"));
|
||||
assert_eq!(vu, Variable::from_valid_name("?vü"));
|
||||
assert_eq!(foo_baz.as_str(), "?foo_baz");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue