Skip to main content

loadsmith_loader/loaders/
macros.rs

1/// Creates a [`globset::Glob`] from a string literal, panicking if the
2/// pattern is invalid.
3///
4/// Intended for use with constant patterns where an invalid glob is a bug.
5///
6/// # Examples
7///
8/// ```rust
9/// use loadsmith_loader::glob;
10///
11/// let g = glob!("version.dll");
12/// let matcher = g.compile_matcher();
13/// assert!(matcher.is_match("version.dll"));
14/// assert!(!matcher.is_match("winmm.dll"));
15/// ```
16#[macro_export]
17macro_rules! glob {
18    ($pattern:expr) => {
19        globset::Glob::new($pattern).expect("constant pattern should be valid")
20    };
21}
22
23/// Creates a [`loadsmith_install::GlobRule`] from a pattern and destination
24/// path literal, panicking if the pattern is invalid.
25///
26/// # Examples
27///
28/// ```rust
29/// use loadsmith_loader::glob_rule;
30/// use loadsmith_install::GlobRule;
31///
32/// let rule: GlobRule = glob_rule!("*.dll" => "plugins");
33/// assert!(rule.matches("mod.dll"));
34/// assert!(!rule.matches("mod.txt"));
35/// ```
36#[macro_export]
37macro_rules! glob_rule {
38    ($pattern:expr => $destination:expr) => {
39        loadsmith_install::GlobRule::new(
40            $crate::glob!($pattern),
41            camino::Utf8Path::new($destination),
42        )
43    };
44}