-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Predicate<PathBuf> for BinaryFilePredicate #74
Comments
I just gave it a try and didn't have any problems #!/usr/bin/env run-cargo-script
//! ```cargo
//! [package]
//! edition="2018"
//! [dependencies]
//! predicates = "1"
//! ```
use predicates::prelude::*;
fn main() {
let actual = std::path::PathBuf::from("Cargo.toml");
let expected = std::path::PathBuf::from("Cargo.toml");
let pred = predicate::path::eq_file(expected);
println!("{}", pred.eval(actual.as_path()));
} Could you clarify where you are having lifetime problems at? |
It worked for you because of that |
Could you provide an example so I can better understand the constraints and we can work out how predicates might be able to change to make it work? |
It's basically like this. The #!/usr/bin/env run-cargo-script
//! ```cargo
//! [package]
//! edition="2018"
//! [dependencies]
//! predicates = "1"
//! ```
fn matches<T, P: Predicate<T>>(value: &T, predicate: P) -> bool {
predicate.eval(value)
}
use predicates::prelude::*;
fn main() {
let actual = std::path::PathBuf::from("Cargo.toml");
let expected = std::path::PathBuf::from("Cargo.toml");
let pred = predicate::path::eq_file(expected);
println!("{}", matches(&actual, pred));
} |
Thanks for the example. For me to better understand the needs / use cases, is there a reason |
Well, there's more generic code in front of that #!/usr/bin/env run-cargo-script
//! ```cargo
//! [package]
//! edition="2018"
//! [dependencies]
//! predicates = "1"
//! ```
fn do_something_with_value<T>(_value: T) {
}
fn do_something_with_value_if_it_matches<T, P>(value: T, predicate: P)
where P: Predicate<T>
{
if matches(&value, predicate) {
do_something_with_value(value)
}
}
fn matches<T, P: Predicate<T>>(value: &T, predicate: P) -> bool {
predicate.eval(value)
}
use predicates::prelude::*;
fn main() {
let actual = std::path::PathBuf::from("Cargo.toml");
let expected = std::path::PathBuf::from("Cargo.toml");
let pred = predicate::path::eq_file(expected);
do_something_with_value_if_it_matches(actual, pred);
} |
btw this is related to #20 where I ran into a lot of problems solving this generically. Some options
|
It would be handy if
BinaryFilePredicate
implementedPredicate<PathBuf>
. There are some functions that, for lifetime reasons, must take a'static
argument, likePathBuf
. Right now those functions can't easily use predicates.The text was updated successfully, but these errors were encountered: