Hi, I was trying out quickcheck today, and stumbled upon the as
keyword in rust. Since I'm new to rust I am not sure I fully understand what this keyword does, except some kind of type casting.
Having this code as an example:
fn dummy() {
fn prop(v: u16) -> TestResult {
assert_eq!(double(v), v * 2);
TestResult::passed()
}
QuickCheck::new().quickcheck(prop as fn(u16) -> TestResult);
}
I don't understand why it's necessary to use prop as fn(u16) -> TestResult
, and why changing that line to QuickCheck::new().quickcheck(prop);
will result in the following error:
QuickCheck::new().quickcheck(prop);
| ^^^^^^^^^^ the traittests::quickcheck::Testable
is not implemented forfn(u16) -> tests::quickcheck::TestResult {tests::dummy::prop}
Is it possible to use a closure ? Something like:
QuickCheck::new().quickcheck(|v: u16| {
assert_eq!(double(v), v * 2);
TestResult::passed()
});
What is the as
keyword doing, and why is it necessary ?
Thank you all for being a great community !