This Rust attribute macro skips running a function that produces a file or a folder (output) depending on a strategy.
#[skip_if(output="avatars.join(name)", strategy="...")]
fn render_avatar(name: &str, avatars: &Path) -> anyhow::Result<()> {
// This will be skipped depending on the strategy.
// e.g. do not run if the output already exists or if the function previously
// failed on these arguments.
Ok(())
}The strategy (specified in the strategy attribute) has access to:
- The arguments hash (excluding the ones provided in the
args_skipattributes); - The source code hash;
- The output path (as provided in the
outputattribute). - A callback with a reference to the result of the method call.
For convenience, the function on which the skip_if attribute is applied can access the value of the output expression through the skip_if_output variable.
The simplest strategy, skip_if::FileExists, is to skip when the output path exists.
#[skip_if(output = "output", strategy = "skip_if::FileExists")]A more advanced strategy, skip_if::Markers, offers the following options:
- Use a marker success file (
{output}.success) with source and arguments hashes to never skip when these change, even if the output file already exists. - Use a marker failure file (
{output}.failure) to skip after a failure.- Optionally, take into account source and argument hashes to retry nevertheless when these change.
- Optionally, mark some errors as retriable.
- Directory mode, where output is assumed to be a directory. The
successandfailuremarkers are stored inside.
#[skip_if(
output = "output",
strategy = "skip_if::Markers::default()",
// or:
// strategy = "skip_if::Markers::default().folder()",
)]- Allow selectively disabling code and argument hashing (they are now tied together).