Skip to main content

DeclarationSource

Trait DeclarationSource 

Source
pub trait DeclarationSource: Sync {
    // Required method
    fn evaluate(
        &self,
        file: &BuildFile,
        discovered: &Discovered,
    ) -> Result<Evaluated>;
}
Expand description

Evaluates one build file and returns what it staged, exactly as written.

The Discovered map holds what discovery targets last produced; a build file that asks for one gets its bytes, or nothing when the map holds none. Load passes the same map to every file it evaluates.

An implementation reports a missing file as Evaluated::Absent rather than as an error: what a missing file means depends on who asked for it, which only the caller knows.

Sync because several build files are evaluated at once, each on the thread that took it.

§Examples

An implementation needs nothing but this crate’s public API:

use std::path::PathBuf;

use buildl_core::{
    BuildFile, DeclarationOrder, DeclarationSource, Directory, Discovered, Evaluated,
    Provenance, Result, StagedFile, StagedSubdir, Written,
};

/// A source in which only the workspace root has a build file, requesting `lib`.
struct RootOnly;

impl DeclarationSource for RootOnly {
    fn evaluate(&self, file: &BuildFile, _discovered: &Discovered) -> Result<Evaluated> {
        if !file.directory().is_root() {
            return Ok(Evaluated::Absent);
        }
        Ok(Evaluated::Staged(StagedFile {
            declarations: Vec::new(),
            subdirs: vec![StagedSubdir {
                path: Written::new("lib"),
                order: DeclarationOrder::new(0),
            }],
        }))
    }
}

let lib = BuildFile::new(Provenance::new(
    PathBuf::from("lib/build.lua"),
    Directory::parse("lib")?,
));
assert_eq!(RootOnly.evaluate(&lib, &Discovered::empty())?, Evaluated::Absent);

Required Methods§

Source

fn evaluate( &self, file: &BuildFile, discovered: &Discovered, ) -> Result<Evaluated>

Evaluates file, giving it discovered to read discovery results from.

§Errors

Returns Error::Evaluation when the file exists but cannot be evaluated.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§