DirChildSingle

Struct DirChildSingle 

Source
pub struct DirChildSingle<T, F: Filter<P>, P: PathType + ?Sized = Path> { /* private fields */ }
Expand description

A structure that represents a directory where only one of the children pass the filter F.

This is useful if you want to select one specific file, by the file prefix / stem, but you don’t care about the extension.

Implementations§

Source§

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

Source

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

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

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

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
assert_eq!(d.value(), &"file".to_owned());
Source

pub fn file_name(&self) -> &P::PathSegmentOwned

Gets the file name of the child (or the name of the directory; the last segment in the path).

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

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
assert_eq!(d.value(), &"file".to_owned());
Source

pub fn file_name_mut(&mut self) -> &mut P::PathSegmentOwned

Gets the file name of the child (or the name of the directory; the last segment in the path). Mutable version of file_name.

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

let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.file_name_mut(), &mut OsString::from("file.txt"));
assert_eq!(d.value_mut(), &mut "file".to_owned());
Source

pub fn value(&self) -> &T

Gets the value of the child.

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

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.value(), &"file".to_owned());
Source

pub fn value_mut(&mut self) -> &mut T

Gets the value of the child. Mutable reference version of Self::value.

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

let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
assert_eq!(d.value_mut(), &mut "file".to_owned());
Source

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

Converts &DirChildSingle<T, F> to DirChildSingle<&T, F>.

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

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d_ref: DirChildSingle<&String, NoFilter> = d.as_ref();
assert_eq!(d_ref.file_name(), &OsString::from("file.txt"));
assert_eq!(d_ref.value(), &&"file".to_owned());
Source

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

Converts &mut DirChildSingle<T, F> to DirChildSingle<&mut T, F>.

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

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

let mut d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let mut d_mut: DirChildSingle<&mut String, NoFilter> = d.as_mut();
d_mut.value_mut().push_str("_modified");
assert_eq!(d.value(), &"file_modified".to_owned());
Source

pub fn map<T2, F2>(self, f: F2) -> DirChildSingle<T2, F, P>
where F2: FnOnce(T) -> T2,

Maps the value of the child to a new value.

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

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d2 = d.map(|s| s.to_uppercase());
assert_eq!(d2.value(), &"FILE".to_owned());
Source

pub fn map_filter<F2>(self) -> DirChildSingle<T, F2, P>
where F2: Filter<P>,

Map the filter to another Filter type.

§Examples
use std::ffi::OsString;
use dir_structure::NoFilter;
use dir_structure::dir_children::DirChildSingle;
use dir_structure::traits::vfs::PathType;

struct Filt;

impl<P: PathType + ?Sized> dir_structure::dir_children::Filter<P> for Filt {
    fn allows(_path: &P) -> bool {
        true
    }
}

let d = DirChildSingle::<_, NoFilter>::new("file.txt", "file".to_owned());
let d2: DirChildSingle<_, Filt> = d.map_filter::<Filt>();
assert_eq!(d2.file_name(), &OsString::from("file.txt"));
assert_eq!(d2.value(), &"file".to_owned());

Trait Implementations§

Source§

impl<T, F: Filter<P>, P: PathType + ?Sized> AssertEq for DirChildSingle<T, F, P>
where for<'__trivial> P::PathSegmentOwned: AssertEq<P::PathSegmentOwned> + Debug, for<'__trivial> T: AssertEq<T> + Debug,

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 DirChildSingle<T, F, P>

Source§

fn clone(&self) -> DirChildSingle<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 DirChildSingle<T, F, P>
where F: Filter<P>, T: Debug, <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, P: PathType + ?Sized> Deref for DirChildSingle<T, F, P>
where F: Filter<P>,

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T, F, P: PathType + ?Sized> DerefMut for DirChildSingle<T, F, P>
where F: Filter<P>,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T: Hash, F: Hash + Filter<P>, P: Hash + PathType + ?Sized> Hash for DirChildSingle<T, F, P>

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: Ord, F: Ord + Filter<P>, P: Ord + PathType + ?Sized> Ord for DirChildSingle<T, F, P>

Source§

fn cmp(&self, other: &DirChildSingle<T, F, P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

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

Source§

fn eq(&self, other: &DirChildSingle<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<T: PartialOrd, F: PartialOrd + Filter<P>, P: PartialOrd + PathType + ?Sized> PartialOrd for DirChildSingle<T, F, P>

Source§

fn partial_cmp(&self, other: &DirChildSingle<T, F, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T, F, Vfs: Vfs<'a>> ReadFrom<'a, Vfs> for DirChildSingle<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: Filter<Vfs::Path>, Vfs: WriteSupportingVfs<'a>> WriteTo<'a, Vfs> for DirChildSingle<T, F, Vfs::Path>
where T: WriteTo<'a, Vfs>,

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 DirChildSingle<T, F, P>
where P::PathSegmentOwned: Eq,

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, F, P> UnwindSafe for DirChildSingle<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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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,