pub struct Vocabulary { /* private fields */ }Expand description
The event vocabulary, read once and shared.
use majordomus_cli::ledger::Vocabulary;
// The default is empty, and an empty vocabulary accepts nothing: a writer that could
// not read the declaration refuses every name rather than allowing any.
let v = Vocabulary::default();
assert!(v.ids().is_empty());
assert!(v.requires("plan_start").is_none());Implementations§
Source§impl Vocabulary
impl Vocabulary
Sourcepub fn load(events_yaml: &Path) -> Result<Self, LedgerError>
pub fn load(events_yaml: &Path) -> Result<Self, LedgerError>
Read share/events.yaml.
The file ships with the tool, so a repository never carries its own: a name this executable does not know is a name nothing in the distribution writes.
use majordomus_cli::ledger::Vocabulary;
let v = Vocabulary::load(&f).unwrap();
assert_eq!(v.ids(), ["plan_done"]);
assert_eq!(v.requires("plan_done"), Some(&["issue".to_string()][..]));
// A file that is not there is an error, never an empty vocabulary that accepts all.
assert!(Vocabulary::load(std::path::Path::new("/nonexistent/events.yaml")).is_err());Sourcepub fn ids(&self) -> &[String]
pub fn ids(&self) -> &[String]
Every declared name, in declaration order. What a refusal lists.
Sourcepub fn requires(&self, event: &str) -> Option<&[String]>
pub fn requires(&self, event: &str) -> Option<&[String]>
The keys a line of this event must carry, or None when the name is not declared.
None and Some(&[]) are different answers: the first is a name nothing declares,
the second a declared event whose envelope is all it needs.
use majordomus_cli::ledger::Vocabulary;
assert!(Vocabulary::default().requires("nothing").is_none());Trait Implementations§
Source§impl Clone for Vocabulary
impl Clone for Vocabulary
Source§fn clone(&self) -> Vocabulary
fn clone(&self) -> Vocabulary
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Vocabulary
impl Debug for Vocabulary
Source§impl Default for Vocabulary
impl Default for Vocabulary
Source§fn default() -> Vocabulary
fn default() -> Vocabulary
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for Vocabulary
impl RefUnwindSafe for Vocabulary
impl Send for Vocabulary
impl Sync for Vocabulary
impl Unpin for Vocabulary
impl UnsafeUnpin for Vocabulary
impl UnwindSafe for Vocabulary
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