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

A struct which represents a (sub)-filestructure.

Implementations§

source§

impl FileStructure

source

pub const fn new(path: String, kind: FileType) -> Self

Basic constructor.

source

pub const fn new_dir(name: String) -> Self

Constructs a dir.

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 wagon_codegen::{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_tokenstream( &mut self, path: &str, data: TokenStream, pretty: bool ) -> Result<Option<&mut Self>>

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

The TokenStream will be converted to a String. If the pretty flag is set, the TokenStream will be prettified first.

Will automatically create directories if needed.

§Errors

Returns a syn::parse::Error if the pretty flag is set and we fail to parse the TokenStream.

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

§

type Item = &'a FileStructure

The type of the elements being iterated over.
§

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

§

type Item = FileStructure

The type of the elements being iterated over.
§

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

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FileStructure

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
§

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

§

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

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

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

§

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

source§

default 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>,

§

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>,

§

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.