DirChild

Struct DirChild 

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

A single child of a DirChildren structure.

Implementations§

Source§

impl<T, P: PathType + ?Sized> DirChild<T, P>

Source

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

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

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;

let d = DirChild::<_, Path>::new("file.txt".to_owned(), "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 std::path::Path;
use dir_structure::dir_children::DirChild;

let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
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 reference version of Self::file_name.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;

let mut d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.file_name(), &OsString::from("file.txt"));
*d.file_name_mut() = OsString::from("new_file.txt");
assert_eq!(d.file_name(), &OsString::from("new_file.txt"));
Source

pub fn value(&self) -> &T

Gets the value of the child.

This is the parsed value of the file / directory.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;

let d = DirChild::<_, Path>::new("file.txt".to_owned(), "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.

This is the parsed value of the file / directory.

Mutable reference version of Self::value.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;

let mut d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.value(), &"file".to_owned());
*d.value_mut() = "new_file".to_owned();
assert_eq!(d.value(), &"new_file".to_owned());
Source

pub fn map_file_name<F, O>(self, f: F) -> Self
where F: FnOnce(P::PathSegmentOwned) -> O, O: Into<P::PathSegmentOwned>,

Maps the file name of this DirChild to a new value.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;

let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.map_file_name(|s| s.to_str().unwrap().to_uppercase()), DirChild::new("FILE.TXT", "file".to_owned()));
Source

pub fn map_value<U, F>(self, f: F) -> DirChild<U, P>
where F: FnOnce(T) -> U,

Maps the value of this DirChild to a new type.

This is useful for converting the value to a different type, for example, if you want to convert the value to a different type of DirStructureItem.

§Examples
use std::ffi::OsString;
use std::path::Path;
use dir_structure::dir_children::DirChild;
use dir_structure::std_types::FileString;

let d = DirChild::<_, Path>::new("file.txt".to_owned(), "file".to_owned());
assert_eq!(d.map_value(|v| FileString(v)), DirChild::new("file.txt".to_owned(), FileString("file".to_owned())));

Trait Implementations§

Source§

impl<T, P: PathType + ?Sized> AssertEq for DirChild<T, 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, P: PathType + ?Sized> Clone for DirChild<T, P>

Source§

fn clone(&self) -> Self

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, P: PathType + ?Sized> Debug for DirChild<T, P>

Source§

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

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

impl<T, P: PathType + ?Sized> Deref for DirChild<T, P>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T, P: PathType + ?Sized> DerefMut for DirChild<T, P>

Source§

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

Mutably dereferences the value.
Source§

impl<T, P: PathType + ?Sized, F> Extend<DirChild<T, P>> for DirChildren<T, F, P>
where F: Filter<P>,

Source§

fn extend<I: IntoIterator<Item = DirChild<T, P>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, P: PathType + ?Sized, F> FromIterator<DirChild<T, P>> for DirChildren<T, F, P>
where F: Filter<P>,

Source§

fn from_iter<I: IntoIterator<Item = DirChild<T, P>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, F, P: PathType + ?Sized> FromIterator<DirChild<T, P>> for ForceCreateDirChildren<T, F, P>
where F: Filter<P>,

Source§

fn from_iter<I: IntoIterator<Item = DirChild<T, P>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: PartialEq, P: PartialEq + PathType + ?Sized> PartialEq for DirChild<T, P>

Source§

fn eq(&self, other: &DirChild<T, 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: Eq, P: Eq + PathType + ?Sized> Eq for DirChild<T, P>
where P::PathSegmentOwned: Eq,

Source§

impl<T, P: PathType + ?Sized> StructuralPartialEq for DirChild<T, P>

Auto Trait Implementations§

§

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

§

impl<T, P> RefUnwindSafe for DirChild<T, P>

§

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

§

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

§

impl<T, P> Unpin for DirChild<T, P>
where <P as PathType>::PathSegmentOwned: Unpin, T: Unpin, P: ?Sized,

§

impl<T, P> UnwindSafe for DirChild<T, 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<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,