DirChildSingleOpt

Enum DirChildSingleOpt 

Source
pub enum DirChildSingleOpt<T, F: Filter<P>, P: PathType + ?Sized = Path> {
    None,
    Some(DirChildSingle<T, F, P>),
}
Expand description

A similar idea to DirChildSingle, but allows for the absence of a matching entry.

Variants§

§

None

The entry is absent.

§

Some(DirChildSingle<T, F, P>)

The entry is present.

Implementations§

Source§

impl<T, F: Filter<P>, P: PathType + ?Sized> DirChildSingleOpt<T, F, P>

Source

pub fn new(file_name: impl Into<P::PathSegmentOwned>, value: T) -> Self

Creates a new DirChildSingleOpt with the specified file name and value.

§Examples
use std::ffi::OsString;
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::NoFilter;

let DirChildSingleOpt::Some(d) = DirChildSingleOpt::<_, NoFilter>::new("file.txt", "file".to_owned()) else {
   panic!("Expected Some variant");
};
assert_eq!(d.file_name(), &OsString::from("file.txt"));
assert_eq!(d.value(), &"file".to_owned());
Source

pub fn is_some(&self) -> bool

Returns true if this is a DirChildSingleOpt::Some.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
assert!(opt.is_some());

let opt = DirChildSingleOpt::<String, NoFilter>::None;
assert!(!opt.is_some());
Source

pub fn is_none(&self) -> bool

Returns true if this is a DirChildSingleOpt::None.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
assert!(!opt.is_none());

let opt = DirChildSingleOpt::<String, NoFilter>::None;
assert!(opt.is_none());
Source

pub fn as_ref(&self) -> DirChildSingleOpt<&T, F, P>

Converts a &DirChildSingleOpt<T, F> into a DirChildSingleOpt<&T, F>.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let opt_ref = opt.as_ref();
assert_eq!(opt_ref, DirChildSingleOpt::Some(DirChildSingle::new("file.txt", &"file".to_owned())));

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let opt_ref = opt.as_ref();
assert_eq!(opt_ref, DirChildSingleOpt::None);
Source

pub fn as_mut(&mut self) -> DirChildSingleOpt<&mut T, F, P>

Converts a &mut DirChildSingleOpt<T, F> into a DirChildSingleOpt<&mut T, F>.

This clones the internal OsString and PathBuf used for the name and path.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;

use dir_structure::NoFilter;

let mut opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let mut opt_mut = opt.as_mut();
if let DirChildSingleOpt::Some(child) = &mut opt_mut {
    child.value_mut().push_str("_modified");
}
assert_eq!(opt, DirChildSingleOpt::Some(DirChildSingle::new("file.txt", "file_modified".to_owned())));

let mut opt = DirChildSingleOpt::<String, NoFilter>::None;
let mut opt_mut = opt.as_mut();
assert_eq!(opt_mut, DirChildSingleOpt::None);
Source

pub fn map<U>( self, f: impl FnOnce(DirChildSingle<T, F, P>) -> DirChildSingle<U, F, P>, ) -> DirChildSingleOpt<U, F, P>

Maps the value inside the DirChildSingleOpt if it exists.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let opt_mapped = opt.map(|child| child.map(|v| v.to_uppercase()));
assert_eq!(opt_mapped, DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "FILE".to_owned())));

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let opt_mapped = opt.map(|child| child.map(|v| v.to_uppercase()));
assert_eq!(opt_mapped, DirChildSingleOpt::None);
Source

pub fn and_then<U, F2: Filter<P2>, P2: PathType + ?Sized>( self, f: impl FnOnce(DirChildSingle<T, F, P>) -> DirChildSingleOpt<U, F2, P2>, ) -> DirChildSingleOpt<U, F2, P2>

Returns a new DirChildSingleOpt by applying the function f to the value inside the DirChildSingleOpt if it exists.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let opt_and_then = opt.and_then(|child| {
    DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new(child.file_name(), child.value().to_uppercase()))
});
assert_eq!(opt_and_then, DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "FILE".to_owned())));

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let opt_and_then = opt.and_then(|child| DirChildSingleOpt::<String, NoFilter>::None);
assert_eq!(opt_and_then, DirChildSingleOpt::None);

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let opt_and_then = opt.and_then(|child| {
    DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new(child.file_name(), child.value().to_uppercase()))
});
assert_eq!(opt_and_then, DirChildSingleOpt::<_, NoFilter>::None);
Source

pub fn or_else<F2: Filter<P>>( self, f: impl FnOnce() -> DirChildSingleOpt<T, F2, P>, ) -> DirChildSingleOpt<T, F2, P>

Returns a new DirChildSingleOpt by applying the function f to the value inside the DirChildSingleOpt if it exists.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned()));
let opt_or_else = opt.or_else(|| {
    DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "FILE".to_owned()))
});
assert_eq!(opt_or_else, DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned())));

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let opt_or_else = opt.or_else(|| {
    DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "FILE".to_owned()))
});
assert_eq!(opt_or_else, DirChildSingleOpt::Some(DirChildSingle::<_, NoFilter>::new("file.txt", "FILE".to_owned())));

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let opt_or_else = opt.or_else(|| DirChildSingleOpt::<String, NoFilter>::None);
assert_eq!(opt_or_else, DirChildSingleOpt::None);
Source

pub fn to_option(self) -> Option<DirChildSingle<T, F, P>>

Converts the DirChildSingleOpt into an Option.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let opt = DirChildSingleOpt::Some(DirChildSingle::new("file.txt", "file".to_owned()));
let option = opt.to_option();
assert_eq!(option, Some(DirChildSingle::<String, NoFilter>::new("file.txt", "file".to_owned())));

let opt = DirChildSingleOpt::<String, NoFilter>::None;
let option = opt.to_option();
assert_eq!(option, None);
Source

pub fn take_if( &mut self, pred: impl FnOnce(&DirChildSingle<T, F, P>) -> bool, ) -> DirChildSingleOpt<T, F, P>

Takes the value out of the DirChildSingleOpt if the predicate pred returns true.

If the predicate returns false, or if the DirChildSingleOpt is None, this returns None.

§Examples
use dir_structure::dir_children::DirChildSingleOpt;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::NoFilter;

let mut opt = DirChildSingleOpt::<String, NoFilter>::Some(DirChildSingle::new("file.txt", "file".to_owned()));
let taken = opt.take_if(|child| child.value() == "file");
assert_eq!(taken, DirChildSingleOpt::Some(DirChildSingle::new("file.txt", "file".to_owned())));
assert_eq!(opt, DirChildSingleOpt::None);

let mut opt = DirChildSingleOpt::<String, NoFilter>::Some(DirChildSingle::new("file.txt", "file".to_owned()));
let taken = opt.take_if(|child| child.value() == "other");
assert_eq!(taken, DirChildSingleOpt::None);
assert_eq!(opt, DirChildSingleOpt::Some(DirChildSingle::new("file.txt", "file".to_owned())));

let mut opt = DirChildSingleOpt::<String, NoFilter>::None;
let taken = opt.take_if(|child| child.value() == "file");
assert_eq!(taken, DirChildSingleOpt::None);
assert_eq!(opt, DirChildSingleOpt::None);

Trait Implementations§

Source§

impl<T, F: Filter<P>, P: PathType + ?Sized> AssertEq for DirChildSingleOpt<T, F, P>

Source§

fn assert_eq( &self, other: &Self, path: &mut AssertPath, init_left: &impl Display, init_right: &impl Display, )

Asserts that self is equal to other, panicking if they are not equal. Read more
Source§

impl<T: Clone, F: Clone + Filter<P>, P: Clone + PathType + ?Sized> Clone for DirChildSingleOpt<T, F, P>

Source§

fn clone(&self) -> DirChildSingleOpt<T, F, P>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, F, P: PathType + ?Sized> Debug for DirChildSingleOpt<T, F, P>
where T: Debug, F: Filter<P>, <P as PathType>::PathSegmentOwned: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, F: Filter<P>, P: PathType + ?Sized> Hash for DirChildSingleOpt<T, F, P>
where T: Hash, <P as PathType>::PathSegmentOwned: Hash,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq, F: PartialEq + Filter<P>, P: PartialEq + PathType + ?Sized> PartialEq for DirChildSingleOpt<T, F, P>

Source§

fn eq(&self, other: &DirChildSingleOpt<T, F, P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T, F, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for DirChildSingleOpt<T, F, Vfs::Path>
where T: ReadFrom<'a, Vfs>, F: Filter<Vfs::Path> + 'a,

Source§

fn read_from(path: &Vfs::Path, vfs: Pin<&'a Vfs>) -> VfsResult<Self, Vfs>
where Self: Sized,

Reads the structure from the specified path, which can be either a file or a directory.
Source§

impl<'a, T, F, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for DirChildSingleOpt<T, F, Vfs::Path>
where T: WriteTo<'a, Vfs>, F: Filter<Vfs::Path>,

Source§

fn write_to(&self, path: &Vfs::Path, vfs: Pin<&'a Vfs>) -> VfsResult<(), Vfs>

Writes the structure to the specified path.
Source§

impl<T: Eq, F: Eq + Filter<P>, P: Eq + PathType + ?Sized> Eq for DirChildSingleOpt<T, F, P>

Source§

impl<T, F: Filter<P>, P: PathType + ?Sized> StructuralPartialEq for DirChildSingleOpt<T, F, P>

Auto Trait Implementations§

§

impl<T, F, P> Freeze for DirChildSingleOpt<T, F, P>
where <P as PathType>::PathSegmentOwned: Freeze, T: Freeze, P: ?Sized,

§

impl<T, F, P> RefUnwindSafe for DirChildSingleOpt<T, F, P>

§

impl<T, F, P> Send for DirChildSingleOpt<T, F, P>
where T: Send, F: Send, P: ?Sized,

§

impl<T, F, P> Sync for DirChildSingleOpt<T, F, P>
where T: Sync, F: Sync, P: ?Sized,

§

impl<T, F, P> Unpin for DirChildSingleOpt<T, F, P>
where <P as PathType>::PathSegmentOwned: Unpin, T: Unpin, F: Unpin, P: Unpin + ?Sized,

§

impl<T, F, P> UnwindSafe for DirChildSingleOpt<T, F, P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DirStructureItem for T

Source§

fn read(path: impl AsRef<<FsVfs as VfsCore>::Path>) -> VfsResult<Self, FsVfs>
where Self: ReadFrom<'static, FsVfs> + Sized,

Uses the ReadFrom implementation to read the structure from disk, from the specified path.
Source§

fn write<'a, 'vfs: 'a>( &'a self, path: impl AsRef<<FsVfs as VfsCore>::Path>, ) -> VfsResult<(), FsVfs>
where Self: WriteTo<'vfs, FsVfs>,

Uses the WriteTo implementation to write the structure to disk at the specified path.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,