Trait Resource

Source
pub trait Resource: Debug {
    // Required method
    fn timestamp(&self) -> Option<SystemTime>;

    // Provided methods
    fn mk_from<F, R, S>(&self, description: &str, src: S, by: F)
       where R: Resource,
             S: AsResource<R>,
             F: FnOnce() { ... }
    fn mk_from_result<E, F, R, S>(
        &self,
        description: &str,
        src: S,
        by: F,
    ) -> Result<(), E>
       where R: Resource,
             S: AsRef<R>,
             F: FnOnce() -> Result<(), E> { ... }
}
Expand description

A resource represents anything that is input or output of a build step.

Typical resources are files and directories with build steps like copying, moving, linking or invoking external commands.

The main resource property is it’s optional timestamp. Build steps should treat output resources without one as out of date and build it unconditionally. When input resource does not have it’s timestamp it should be considered as changed and therefore rebuild the output the same way as when input is newer the output. Typical scenario for lack or timestamp is when output resources do not exists yet (clean builds)

Required Methods§

Source

fn timestamp(&self) -> Option<SystemTime>

Name of the resource used for logging and error reporting Return resource timestamp. Can be None for input resources that should be considered as changed in every build run or output resources that do not exists yet.

Provided Methods§

Source

fn mk_from<F, R, S>(&self, description: &str, src: S, by: F)
where R: Resource, S: AsResource<R>, F: FnOnce(),

Build the resource form a given src resource as a side product of given function by respecting resource timestamps meaning that function by will only be ran if the output needs to be build.

This method forces the by function to handle any errors on it’s own and stop Cargo build using a panic. To propagate the error, use mk_from_result()

Source

fn mk_from_result<E, F, R, S>( &self, description: &str, src: S, by: F, ) -> Result<(), E>
where R: Resource, S: AsRef<R>, F: FnOnce() -> Result<(), E>,

Same as mk_from() with error propagation

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<R> Resource for Vec<R>
where R: Resource,

Implementors§