simple-fs 0.12.1

Simple and convenient API for File System access
Documentation
/// Note: In the future, the lifetime might be removed, and iter_files will take Option<&ListOptions>.
#[derive(Default)]
pub struct ListOptions<'a> {
	pub exclude_globs: Option<Vec<&'a str>>,

	/// When this is true,
	/// - the glob will be relative to the directory of the list, rather than including it.
	///
	/// By default, it is false.
	pub relative_glob: bool,

	/// For now, only used in dir list
	pub depth: Option<usize>,
}

/// Constructors
impl<'a> ListOptions<'a> {
	pub fn new(globs: Option<&'a [&'a str]>) -> Self {
		ListOptions {
			exclude_globs: globs.map(|v| v.to_vec()),
			relative_glob: false,
			depth: None,
		}
	}

	pub fn from_relative_glob(val: bool) -> Self {
		ListOptions {
			exclude_globs: None,
			relative_glob: val,
			depth: None,
		}
	}
}

/// Setters
impl<'a> ListOptions<'a> {
	pub fn with_exclude_globs(mut self, globs: &'a [&'a str]) -> Self {
		self.exclude_globs = Some(globs.to_vec());
		self
	}

	pub fn with_relative_glob(mut self) -> Self {
		self.relative_glob = true;
		self
	}
}

/// Getters
impl<'a> ListOptions<'a> {
	pub fn exclude_globs(&'a self) -> Option<&'a [&'a str]> {
		self.exclude_globs.as_deref()
	}
}

// region:    --- Froms

impl<'a> From<&'a [&'a str]> for ListOptions<'a> {
	fn from(globs: &'a [&'a str]) -> Self {
		ListOptions {
			exclude_globs: Some(globs.to_vec()),
			relative_glob: false,
			depth: None,
		}
	}
}

impl<'a> From<Option<&'a [&'a str]>> for ListOptions<'a> {
	fn from(globs: Option<&'a [&'a str]>) -> Self {
		ListOptions {
			exclude_globs: globs.map(|v| v.to_vec()),
			relative_glob: false,
			depth: None,
		}
	}
}

impl<'a> From<Vec<&'a str>> for ListOptions<'a> {
	fn from(globs: Vec<&'a str>) -> Self {
		let globs_ref: Vec<&'a str> = globs.to_vec();
		ListOptions {
			exclude_globs: Some(globs_ref),
			relative_glob: false,
			depth: None,
		}
	}
}

// endregion: --- Froms