Skip to main content

Presence

Trait Presence 

Source
pub trait Presence {
    // Required methods
    fn executable(&self, name: &str) -> bool;
    fn variable(&self, name: &str) -> bool;
}
Expand description

What the crate can observe about an advisor’s installation. The one seam tests fake: SystemPresence reads the process, and an example or a test answers from a list.

use majordomus_cli::reasoning::availability::Presence;

struct Listed(&'static [&'static str]);
impl Presence for Listed {
    fn executable(&self, name: &str) -> bool { self.0.contains(&name) }
    fn variable(&self, name: &str) -> bool { self.0.contains(&name) }
}
let p: &dyn Presence = &Listed(&["tool", "ACME_KEY"]);
assert!(p.executable("tool") && p.variable("ACME_KEY"));
assert!(!p.executable("other"));

Required Methods§

Source

fn executable(&self, name: &str) -> bool

Whether an executable of this name is on PATH: what says a client tool or a local runtime is installed.

use majordomus_cli::reasoning::availability::Presence;

struct Only(&'static str);
impl Presence for Only {
    fn executable(&self, name: &str) -> bool { name == self.0 }
    fn variable(&self, _: &str) -> bool { false }
}
assert!(Only("tool").executable("tool"));
assert!(!Only("tool").executable("other"));
Source

fn variable(&self, name: &str) -> bool

Whether an environment variable of this name is set and non-empty: what says an API advisor’s credential is configured. Never its value.

use majordomus_cli::reasoning::availability::Presence;

struct Only(&'static str);
impl Presence for Only {
    fn executable(&self, _: &str) -> bool { false }
    fn variable(&self, name: &str) -> bool { name == self.0 }
}
assert!(Only("ACME_KEY").variable("ACME_KEY"));
assert!(!Only("ACME_KEY").variable("OTHER_KEY"));

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§