pub struct RouteRule { /* private fields */ }Expand description
A route-based install rule that maps files by directory name and file extension.
A RouteRule looks for a named directory component in the input path and maps
the remaining suffix into the target directory. File extensions can be used as
an additional matching criterion.
§Examples
use camino::Utf8PathBuf;
use loadsmith_core::{PackageRef, PackageId, Version};
use loadsmith_install::RouteRule;
let rule = RouteRule::new_static("BepInEx\\plugins")
.with_file_extension("dll");
let pkg = PackageRef::new(PackageId::new("x753-More_Suits"), Version::new(1, 0, 3));
assert!(rule.matches("MyPlugin.dll"));
assert!(rule.matches_path("BepInEx\\plugins\\MyPlugin.dll"));
assert_eq!(
rule.map_file("plugins\\MyPlugin.dll", &pkg),
Some(Utf8PathBuf::from("BepInEx\\plugins\\x753-More_Suits\\MyPlugin.dll"))
);Implementations§
Source§impl RouteRule
impl RouteRule
Sourcepub fn new_static(path: &'static str) -> Self
pub fn new_static(path: &'static str) -> Self
Creates a route rule from a static path string. The rule name is derived from the last path component.
Sourcepub fn new(path: impl Into<Cow<'static, Utf8Path>>) -> Self
pub fn new(path: impl Into<Cow<'static, Utf8Path>>) -> Self
Creates a route rule from any path. The rule name is derived from the last path component.
Sourcepub fn new_with_target(
name: impl Into<Cow<'static, str>>,
target: impl Into<Cow<'static, Utf8Path>>,
) -> Self
pub fn new_with_target( name: impl Into<Cow<'static, str>>, target: impl Into<Cow<'static, Utf8Path>>, ) -> Self
Creates a route rule with an explicit name and target path.
The name is the directory component that triggers a match; target is
the directory where matched files are installed.
Sourcepub fn with_file_extension(
self,
extension: impl Into<Cow<'static, str>>,
) -> Self
pub fn with_file_extension( self, extension: impl Into<Cow<'static, str>>, ) -> Self
Adds a file extension to the matching set.
Sourcepub fn with_file_extensions(self, extensions: Vec<Cow<'static, str>>) -> Self
pub fn with_file_extensions(self, extensions: Vec<Cow<'static, str>>) -> Self
Replaces the entire set of matching file extensions.
Sourcepub fn with_flatten(self, flatten: bool) -> Self
pub fn with_flatten(self, flatten: bool) -> Self
Sets whether to flatten the mapped path (remove intermediate directories).
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 with_mutable(self, mutable: bool) -> Self
pub fn with_mutable(self, mutable: bool) -> Self
Sets whether the rule allows mutable (user-modifiable) files.
Sourcepub fn matches(&self, path: impl AsRef<Utf8Path>) -> bool
pub fn matches(&self, path: impl AsRef<Utf8Path>) -> bool
Returns true if the path matches by extension or by route name.
Sourcepub fn matches_extension(&self, path: impl AsRef<Utf8Path>) -> bool
pub fn matches_extension(&self, path: impl AsRef<Utf8Path>) -> bool
Returns true if the file name has one of the rule’s registered extensions.
Sourcepub fn matches_path(&self, path: impl AsRef<Utf8Path>) -> bool
pub fn matches_path(&self, path: impl AsRef<Utf8Path>) -> bool
Returns true if the path contains the route’s name as a path component.
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.
If the path contains the route name, the part before the route name becomes
the prefix; otherwise the parent directory becomes the prefix. When subdir
is enabled the package ID is inserted as an intermediate directory. When
flatten is disabled the prefix is preserved in the output.
Sourcepub fn use_links(&self) -> bool
pub fn use_links(&self) -> bool
Returns true if the rule prefers hard links over file copies.
Links are used when the rule is not marked as mutable.
Sourcepub fn conflict_strategy(&self) -> ConflictStrategy
pub fn conflict_strategy(&self) -> ConflictStrategy
Returns the conflict strategy for this route rule (always Skip).
Route rules never overwrite existing files and never error; they silently skip.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RouteRule
impl<'de> Deserialize<'de> for RouteRule
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 RouteRule
Source§impl From<RouteRule> for InstallRule
impl From<RouteRule> for InstallRule
impl StructuralPartialEq for RouteRule
Auto Trait Implementations§
impl Freeze for RouteRule
impl RefUnwindSafe for RouteRule
impl Send for RouteRule
impl Sync for RouteRule
impl Unpin for RouteRule
impl UnsafeUnpin for RouteRule
impl UnwindSafe for RouteRule
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.