Add InstanceMetadata builder (#269)

* Add InstanceMetadata builder, with context field for globbing

* Revert snapshot changes

* Port snapshot functions to InstanceMetadata builder-ish pattern

* Remove IgnoreGlob struct

* Elide lifetime
This commit is contained in:
Lucien Greathouse 2019-12-03 14:49:40 -08:00 • committed by GitHub
parent da6c7b4d7a
commit a48c238ed7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 39 deletions

View file

@ -1,4 +1,7 @@
use std::{fmt, path::PathBuf};
use std::{
fmt,
path::{Path, PathBuf},
};
use serde::{Deserialize, Serialize};
@ -42,14 +45,41 @@ pub struct InstanceMetadata {
pub relevant_paths: Vec<PathBuf>,
}
impl Default for InstanceMetadata {
fn default() -> Self {
InstanceMetadata {
impl InstanceMetadata {
pub fn new() -> Self {
Self {
ignore_unknown_instances: false,
instigating_source: None,
relevant_paths: Vec::new(),
}
}
pub fn ignore_unknown_instances(self, ignore_unknown_instances: bool) -> Self {
Self {
ignore_unknown_instances,
..self
}
}
pub fn instigating_source(self, instigating_source: impl Into<InstigatingSource>) -> Self {
Self {
instigating_source: Some(instigating_source.into()),
..self
}
}
pub fn relevant_paths(self, relevant_paths: Vec<PathBuf>) -> Self {
Self {
relevant_paths,
..self
}
}
}
impl Default for InstanceMetadata {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, PartialEq, Serialize, Deserialize)]
@ -74,3 +104,9 @@ impl From<PathBuf> for InstigatingSource {
InstigatingSource::Path(path)
}
}
impl From<&Path> for InstigatingSource {
fn from(path: &Path) -> Self {
InstigatingSource::Path(path.to_path_buf())
}
}