Struct wagon_codegen::FileStructure
source · 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
source§fn eq(&self, other: &FileStructure) -> bool
fn eq(&self, other: &FileStructure) -> bool
self
and other
values to be equal, and is used
by ==
.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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.