Skip to main content

FileStructure

Struct FileStructure 

Source
pub struct FileStructure { /* private fields */ }
Expand description

A struct which represents a (sub)-filestructure.

Implementations§

Source§

impl FileStructure

Source

pub fn from_path(path: &str) -> Self

Constructs a FileStructure completely from a unix path.

If the path contains a starting /, will return a structure with a root node. If not, the root will be the first name of the path.

§Example
use filestructure::{FileStructure, FileType};
let s = "/some/path";
let fs = FileStructure::from_path(s);
let expected = FileStructure::new("".to_string(), 
    FileType::Dir(vec![
        FileStructure::new("some".to_string(),
            FileType::Dir(vec![
                FileStructure::new("path".to_string(),
                    FileType::Dir(vec![])
                )
            ])
        )
    ])
);
assert_eq!(fs, expected);
Source

pub fn write_to_disk(&self, root: &Path) -> Result<()>

Given a full FileStructure and a starting path, attempts to write it all to disk.

Directories are handled recursively. Everything else is converted to bytes and written to a specific file.

§Errors

Errors whenever we fail to either write to a file or create a dir. See the documentation for File::create, Write::write_all and create_dir for more info.

Source

pub fn get(&self, path: &str) -> Option<&Self>

Tries finding a file in the structure by its full path.

Path should be written unix style.

Source

pub fn get_mut(&mut self, path: &str) -> Option<&mut Self>

Tries finding a file in the structure by its full path, mutably

Path should be written unix style.

Source

pub fn insert_dir(&mut self, path: &str) -> Option<&mut Self>

Inserts a directory into the FileStructure. Returns a None if we fail, returns a mutable reference to the bottom directory if we succeed.

Functions like mkdir -p, meaning that it will automatically create directories as needed until the full path has been added.

Source

pub fn insert_blob(&mut self, path: &str, blob: Box<[u8]>) -> Option<&mut Self>

Insert binary blob data at some path relative to the root FileStructure.

Will automatically create directories if needed.

Source

pub fn insert_string(&mut self, path: &str, data: String) -> Option<&mut Self>

Insert a String at some path relative to the root FileStructure.

Will automatically create directories if needed.

Source

pub fn insert(&mut self, child: Self) -> Option<&mut Self>

Insert a FileStructure as a child to this FileStructure.

Returns a None if this FileStructure is not a directory. Returns a mutable reference to the child otherwise.

Source

pub fn get_path(&self) -> &str

Get the path for this node of the structure.

Source

pub fn len(&self) -> usize

Get the “len” (file count) of the structure.

TODO: Precalculate this instead of exploring the whole tree.

Source

pub fn is_empty(&self) -> bool

A filestructure is deemed empty if there are 0 and 0 subdirs in it.

Source

pub fn iter(&self) -> FileIterator<'_>

Convert the FileStructure into a usable iterator.

This will iterate over all the nodes in a DFS style.

Trait Implementations§

Source§

impl Debug for FileStructure

Source§

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

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

impl Default for FileStructure

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for FileStructure

Source§

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

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

impl Eq for FileStructure

Source§

impl IntoIterator for FileStructure

Source§

type Item = FileStructure

The type of the elements being iterated over.
Source§

type IntoIter = OwnedFileIterator

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<'a> IntoIterator for &'a FileStructure

Source§

type Item = &'a FileStructure

The type of the elements being iterated over.
Source§

type IntoIter = FileIterator<'a>

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 PartialEq for FileStructure

Source§

fn eq(&self, other: &FileStructure) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for FileStructure

Auto Trait Implementations§

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.