pub struct FileStructure { /* private fields */ }Expand description
A struct which represents a (sub)-filestructure.
Implementations§
Source§impl FileStructure
impl FileStructure
Sourcepub fn from_path(path: &str) -> Self
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);Sourcepub fn write_to_disk(&self, root: &Path) -> Result<()>
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.
Sourcepub fn get(&self, path: &str) -> Option<&Self>
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.
Sourcepub fn get_mut(&mut self, path: &str) -> Option<&mut Self>
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.
Sourcepub fn insert_dir(&mut self, path: &str) -> Option<&mut Self>
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.
Sourcepub fn insert_blob(&mut self, path: &str, blob: Box<[u8]>) -> Option<&mut Self>
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.
Sourcepub fn insert_string(&mut self, path: &str, data: String) -> Option<&mut Self>
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.
Sourcepub fn insert_tokenstream(
&mut self,
path: &str,
data: TokenStream,
pretty: bool,
) -> Result<Option<&mut Self>>
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.
Sourcepub fn insert(&mut self, child: Self) -> Option<&mut Self>
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Get the “len” (file count) of the structure.
TODO: Precalculate this instead of exploring the whole tree.
Trait Implementations§
Source§impl Debug for FileStructure
impl Debug for FileStructure
Source§impl Default for FileStructure
impl Default for FileStructure
Source§impl Display for FileStructure
impl Display for FileStructure
Source§impl<'a> IntoIterator for &'a FileStructure
impl<'a> IntoIterator for &'a FileStructure
Source§impl IntoIterator for FileStructure
impl IntoIterator for FileStructure
Source§impl PartialEq for FileStructure
impl PartialEq for FileStructure
impl Eq for FileStructure
impl StructuralPartialEq for FileStructure
Auto Trait Implementations§
impl Freeze for FileStructure
impl RefUnwindSafe for FileStructure
impl Send for FileStructure
impl Sync for FileStructure
impl Unpin for FileStructure
impl UnwindSafe for FileStructure
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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