pub struct InstallRuleset<'a> { /* private fields */ }Expand description
A borrowed set of install rules used to map and filter package files.
InstallRuleset holds references to an existing rules slice, an optional
exclude glob set, and an optional default rule. Use OwnedInstallRuleset
when you need owned storage.
§Examples
use camino::{Utf8Path, Utf8PathBuf};
use loadsmith_core::{PackageRef, PackageId, Version};
use loadsmith_install::{InstallRuleset, InstallRule, GlobRule};
let rules = [
InstallRule::Glob(GlobRule::try_from_pattern("*.dll", Utf8Path::new("BepInEx/plugins")).unwrap()),
];
let ruleset = InstallRuleset::new(&rules);
let pkg = PackageRef::new(PackageId::new("x753-More_Suits"), Version::new(1, 0, 3));
assert_eq!(
ruleset.map_file("MyPlugin.dll", &pkg),
Some(Utf8PathBuf::from("BepInEx/plugins/MyPlugin.dll"))
);Implementations§
Source§impl<'a> InstallRuleset<'a>
impl<'a> InstallRuleset<'a>
Sourcepub const fn new(rules: &'a [InstallRule]) -> Self
pub const fn new(rules: &'a [InstallRule]) -> Self
Creates a new InstallRuleset from a slice of rules.
Sourcepub fn with_default_rule(self, default_rule: &'a InstallRule) -> Self
pub fn with_default_rule(self, default_rule: &'a InstallRule) -> Self
Sets the default rule used when no other rule matches a file.
Sourcepub fn with_exclude(self, exclude: &'a GlobSet) -> Self
pub fn with_exclude(self, exclude: &'a GlobSet) -> Self
Sets a glob set for excluding files from installation.
Sourcepub fn rules(&self) -> &[InstallRule]
pub fn rules(&self) -> &[InstallRule]
Returns the list of install rules.
Sourcepub fn default_rule(&self) -> Option<&InstallRule>
pub fn default_rule(&self) -> Option<&InstallRule>
Returns the default rule, if any.
Sourcepub fn find_rule_for_path(
&self,
path: impl AsRef<Utf8Path>,
) -> Option<&'a InstallRule>
pub fn find_rule_for_path( &self, path: impl AsRef<Utf8Path>, ) -> Option<&'a InstallRule>
Finds the first rule that matches the given path, falling back to the default rule if no path or extension match is found.
Path-based matches are checked before extension-based matches.
Sourcepub fn find_rule_for_mapped_path(
&self,
path: impl AsRef<Utf8Path>,
) -> Option<&'a InstallRule>
pub fn find_rule_for_mapped_path( &self, path: impl AsRef<Utf8Path>, ) -> Option<&'a InstallRule>
Finds the first rule whose mapped output path starts with the given path.
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 through the ruleset, returning the install destination.
Returns None if the file is excluded or no rule matches.
Sourcepub fn map_file_and_return_rule(
&self,
path: impl AsRef<Utf8Path>,
package: &PackageRef,
) -> Option<(Utf8PathBuf, &InstallRule)>
pub fn map_file_and_return_rule( &self, path: impl AsRef<Utf8Path>, package: &PackageRef, ) -> Option<(Utf8PathBuf, &InstallRule)>
Maps a file path and returns the install destination together with the matching rule.
Returns None if the file is excluded or no rule matches.
Sourcepub fn is_excluded(&self, path: impl AsRef<Path>) -> bool
pub fn is_excluded(&self, path: impl AsRef<Path>) -> bool
Returns true if the path matches the exclude glob set.
Trait Implementations§
Source§impl<'a> Clone for InstallRuleset<'a>
impl<'a> Clone for InstallRuleset<'a>
Source§fn clone(&self) -> InstallRuleset<'a>
fn clone(&self) -> InstallRuleset<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more