pub struct GlobRule { /* private fields */ }Expand description
A glob-based install rule that maps matching files to a target directory.
A GlobRule matches files by a glob pattern and maps them into a target
directory, with optional path stripping and subdirectory creation.
§Examples
use std::borrow::Cow;
use camino::{Utf8Path, Utf8PathBuf};
use globset::Glob;
use loadsmith_core::{PackageRef, PackageId, Version};
use loadsmith_install::GlobRule;
let rule = GlobRule::try_from_pattern("*.dll", Utf8Path::new("BepInEx/plugins")).unwrap();
let pkg = PackageRef::new(PackageId::new("x753-More_Suits"), Version::new(1, 0, 3));
assert!(rule.matches("MyPlugin.dll"));
assert!(!rule.matches("config.txt"));
assert_eq!(
rule.map_file("MyPlugin.dll", &pkg),
Some(Utf8PathBuf::from("BepInEx/plugins/MyPlugin.dll"))
);Implementations§
Source§impl GlobRule
impl GlobRule
Sourcepub fn new(pattern: Glob, target: impl Into<Cow<'static, Utf8Path>>) -> Self
pub fn new(pattern: Glob, target: impl Into<Cow<'static, Utf8Path>>) -> Self
Creates a new GlobRule from a compiled Glob pattern and a target path.
Sourcepub fn try_from_pattern(
pattern: impl AsRef<str>,
target: impl Into<Cow<'static, Utf8Path>>,
) -> Result<Self, Error>
pub fn try_from_pattern( pattern: impl AsRef<str>, target: impl Into<Cow<'static, Utf8Path>>, ) -> Result<Self, Error>
Creates a new GlobRule by compiling a glob pattern string.
Returns a globset::Error if the pattern is invalid.
Sourcepub fn strip_top_level(self, strip_top_level: bool) -> Self
pub fn strip_top_level(self, strip_top_level: bool) -> Self
Strips the top-level directory component from paths before mapping.
Sourcepub fn strip_levels(self, strip_levels: usize) -> Self
pub fn strip_levels(self, strip_levels: usize) -> Self
Strips the given number of leading path components before mapping.
Sourcepub fn use_links(self, use_links: bool) -> Self
pub fn use_links(self, use_links: bool) -> Self
Sets whether to use hard links instead of copying files.
Sourcepub fn with_subdir(self, subdir: bool) -> Self
pub fn with_subdir(self, subdir: bool) -> Self
Sets whether to create a subdirectory named after the package ID inside the target directory.
Sourcepub fn matches(&self, path: impl AsRef<Utf8Path>) -> bool
pub fn matches(&self, path: impl AsRef<Utf8Path>) -> bool
Returns true if the path matches this rule’s glob pattern.
Sourcepub fn map_file(
&self,
path: impl AsRef<Utf8Path>,
package: &PackageRef,
) -> Option<Utf8PathBuf>
pub fn map_file( &self, path: impl AsRef<Utf8Path>, package: &PackageRef, ) -> Option<Utf8PathBuf>
Maps a file path to its install destination under the rule’s target directory.
Returns None if stripping removes all path components. When subdir is
enabled the package ID is inserted as an intermediate directory.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for GlobRule
impl<'de> Deserialize<'de> for GlobRule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for GlobRule
Source§impl From<GlobRule> for InstallRule
impl From<GlobRule> for InstallRule
impl StructuralPartialEq for GlobRule
Auto Trait Implementations§
impl Freeze for GlobRule
impl RefUnwindSafe for GlobRule
impl Send for GlobRule
impl Sync for GlobRule
impl Unpin for GlobRule
impl UnsafeUnpin for GlobRule
impl UnwindSafe for GlobRule
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.