pub struct DirChildren<T>where
    T: DirStructureItem,{
    pub self_path: PathBuf,
    pub children: Vec<DirChild<T>>,
}
Expand description

A directory structure where we don’t know the names of the folders at compile-time, and as such we cannot use the derive macro.

Instead we know that all the entries in the directory are folders, and that they all have the same structure inside (defined by the [T] type parameter), or they are all files (which can be read with DirChildren<String> for example).

In either case, [<T as ReadFrom>::read_from] must be able to read all the entries in the directory.

The WriteTo implementation will directly write the children to the directory it is passed, with no regards to the path stored in self_path.

Fields§

§self_path: PathBuf

The path to the root directory.

This path doesn’t influence writing in any way, it is only to point out the directory after it has been read and parsed.

§children: Vec<DirChild<T>>

The children of the root directory.

Implementations§

source§

impl<T> DirChildren<T>where T: DirStructureItem,

source

pub fn new() -> Self

Creates an empty DirChildren, with no children.

source

pub fn with_children_from_iter( self_path: impl Into<PathBuf>, children: impl IntoIterator<Item = DirChild<T>> ) -> Self

Creates a DirChildren with the given path and children.

source

pub fn len(&self) -> usize

Returns the number of children.

source

pub fn get(&self, index: usize) -> Option<&DirChild<T>>

Gets the child at the specified index.

source

pub fn get_name(&self, name: impl AsRef<OsStr>) -> Option<&DirChild<T>>

Gets the child with the specified “file” name (last segment of path).

source

pub fn iter(&self) -> DirChildrenIter<'_, T>

Returns an iterator over the children.

Trait Implementations§

source§

impl<T> IntoIterator for DirChildren<T>where T: DirStructureItem,

§

type Item = DirChild<T>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<DirChildren<T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> ReadFrom for DirChildren<T>where T: DirStructureItem,

source§

fn read_from(path: &Path) -> Result<Self>where Self: Sized,

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

impl<T> WriteTo for DirChildren<T>where T: DirStructureItem,

source§

fn write_to(&self, path: &Path) -> Result<()>

Writes the structure to the specified path.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for DirChildren<T>where T: RefUnwindSafe,

§

impl<T> Send for DirChildren<T>where T: Send,

§

impl<T> Sync for DirChildren<T>where T: Sync,

§

impl<T> Unpin for DirChildren<T>where T: Unpin,

§

impl<T> UnwindSafe for DirChildren<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> DirStructureItem for Twhere T: ReadFrom + WriteTo,

source§

fn read(path: impl AsRef<Path>) -> Result<Self>where Self: Sized,

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

fn write(&self, path: impl AsRef<Path>) -> Result<()>

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.