pub struct ChangeDetection;
Expand description
A change detection entry point.
Creates a builder to generate change detection instructions.
§Examples
use change_detection::ChangeDetection;
fn main() {
ChangeDetection::path("src/hello.c").generate();
}
This is the same as just write:
fn main() {
println!("cargo:rerun-if-changed=src/hello.c");
}
You can collect resources from a path:
fn main() {
ChangeDetection::path("some_path").generate();
}
To chain multiple directories and files:
fn main() {
ChangeDetection::path("src/hello.c")
.path("static")
.path("build.rs")
.generate();
}
Implementations§
Source§impl ChangeDetection
impl ChangeDetection
Sourcepub fn path<P>(path: P) -> ChangeDetectionBuilder
pub fn path<P>(path: P) -> ChangeDetectionBuilder
Collects change detection instructions from a path
.
A path
can be a single file or a directory.
§Examples:
To generate change instructions for the directory with the name static
:
ChangeDetection::path("static").generate();
To generate change instructions for the file with the name build.rs
:
ChangeDetection::path("build.rs").generate();
Sourcepub fn path_include<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
pub fn path_include<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
Collects change detection instructions from a path
applying include filter
.
A path
can be a single file or a directory.
§Examples:
To generate change instructions for the directory with the name static
but only for files ending with b
:
ChangeDetection::path_include("static", |path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().ends_with("b"))
.unwrap_or(false)
}).generate();
Sourcepub fn path_exclude<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
pub fn path_exclude<P, F>(path: P, filter: F) -> ChangeDetectionBuilder
Collects change detection instructions from a path
applying exclude filter
.
A path
can be a single file or a directory.
§Examples:
To generate change instructions for the directory with the name static
but without files ending with b
:
ChangeDetection::path_exclude("static", |path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().ends_with("b"))
.unwrap_or(false)
}).generate();
Sourcepub fn path_filter<P, F1, F2>(
path: P,
include: F1,
exclude: F2,
) -> ChangeDetectionBuilder
pub fn path_filter<P, F1, F2>( path: P, include: F1, exclude: F2, ) -> ChangeDetectionBuilder
Collects change detection instructions from a path
applying include
and exclude
filters.
A path
can be a single file or a directory.
§Examples:
To generate change instructions for the directory with the name static
including only files starting with a
but without files ending with b
:
ChangeDetection::path_filter("static", |path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().starts_with("a"))
.unwrap_or(false)
}, |path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().ends_with("b"))
.unwrap_or(false)
}).generate();
Sourcepub fn include<F>(filter: F) -> ChangeDetectionBuilderwhere
F: PathMatcher + 'static,
pub fn include<F>(filter: F) -> ChangeDetectionBuilderwhere
F: PathMatcher + 'static,
Applies a global include
filter to all paths.
§Examples:
To included only files starting with a
for paths static1
, static2
and static3
:
ChangeDetection::include(|path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().starts_with("a"))
.unwrap_or(false)
})
.path("static1")
.path("static2")
.path("static3")
.generate();
Sourcepub fn exclude<F>(filter: F) -> ChangeDetectionBuilderwhere
F: PathMatcher + 'static,
pub fn exclude<F>(filter: F) -> ChangeDetectionBuilderwhere
F: PathMatcher + 'static,
Applies a global exclude
filter to all paths.
§Examples:
To exclude files starting with a
for paths static1
, static2
and static3
:
ChangeDetection::exclude(|path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().starts_with("a"))
.unwrap_or(false)
})
.path("static1")
.path("static2")
.path("static3")
.generate();
Sourcepub fn filter<F1, F2>(include: F1, exclude: F2) -> ChangeDetectionBuilderwhere
F1: PathMatcher + 'static,
F2: PathMatcher + 'static,
pub fn filter<F1, F2>(include: F1, exclude: F2) -> ChangeDetectionBuilderwhere
F1: PathMatcher + 'static,
F2: PathMatcher + 'static,
Applies a global include
and exclude
filters to all paths.
§Examples:
To include files starting with a
for paths static1
, static2
and static3
, but whose names do not end in b
:
ChangeDetection::filter(|path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().starts_with("a"))
.unwrap_or(false)
}, |path: &std::path::Path| {
path.file_name()
.map(|filename| filename.to_str().unwrap().ends_with("b"))
.unwrap_or(false)
})
.path("static1")
.path("static2")
.path("static3")
.generate();