pub struct Output {
pub path: PathBuf,
}Expand description
Allows defining a cached file output and when it should be rebuilt.
Example usage:
use std::{fs, path::PathBuf};
let output_path = PathBuf::from("my/build/result.txt");
cicero_cache::Output::from(output_path.clone()).rebuild_on_change([
PathBuf::from("my/build/input.csv"),
], || {
if output_path.exists() {
fs::remove_file(&output_path)?;
}
if let Some(parent_dir) = output_path.parent() {
fs::create_dir_all(parent_dir)?;
}
fs::File::create(output_path)?;
Ok(())
});Fields§
§path: PathBufFile path that results from the cached action.
Implementations§
Source§impl Output
impl Output
Sourcepub fn rebuild_on_change(
&self,
inputs: impl AsRef<[PathBuf]>,
code: impl FnOnce() -> Result<()>,
) -> Result<()>
pub fn rebuild_on_change( &self, inputs: impl AsRef<[PathBuf]>, code: impl FnOnce() -> Result<()>, ) -> Result<()>
Executes the provided closures, if one of the
provided inputs or the provided Output::path
changed from the previous run.
In this case, the result of the closure is returned as an Ok(Some(_)).
If the closure did not get executed, an Ok(None) is returned.
If an error occurs in the provided closure, the result is not cached and the error is returned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Output
impl RefUnwindSafe for Output
impl Send for Output
impl Sync for Output
impl Unpin for Output
impl UnsafeUnpin for Output
impl UnwindSafe for Output
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
Mutably borrows from an owned value. Read more