pub struct Shape<T: ShapeDescribe> { /* private fields */ }Expand description
Shape is a struct used to create directory with a specified Shape
in the example below we are defining shaped like so
the directory will contain
- a file named “my_file.txt” and it’s identifier (the named that we will access it with in our code) will be “my_file”
- a directory called “my_dir”
- a directory that will contain
- a file named “child_file.txt” and it’s identifier will be “child_file”
example:
use fs_pro::{File, Dir, Shape};
#[derive(Shape)]
struct ChildShapedDir {
#[name = "child_file.txt"]
child_file: File
/// ...
}
#[derive(Shape)]
struct MyShapedDir {
#[name = "my_file.txt"]
my_file: File,
#[pattern = "*.txt"]
my_dir: Dir,
child_shaped_dir: ChildShapedDir
}
fn main() {
let shape: Shape<MyShapedDir> = Shape::new();
let shape_inst = shape.create_at("target").unwrap();
println!("{:?}", shape_inst.my_file); // File
println!("{:?}", shape_inst.my_dir); // Dir
println!("{:?}", shape_inst.child_shaped_dir.child_file); // File
}Implementations§
Source§impl<T: ShapeDescribe> Shape<T>
impl<T: ShapeDescribe> Shape<T>
Sourcepub fn create_at<'a, P: 'a + AsRef<Path>>(&self, path: P) -> Result<T, Error>
pub fn create_at<'a, P: 'a + AsRef<Path>>(&self, path: P) -> Result<T, Error>
create the shape in a directory
Sourcepub fn create_at_hook<'a, P: 'a + AsRef<Path>>(
&self,
path: P,
hook: &'a dyn Fn(PathBuf, bool),
) -> Result<T, Error>
pub fn create_at_hook<'a, P: 'a + AsRef<Path>>( &self, path: P, hook: &'a dyn Fn(PathBuf, bool), ) -> Result<T, Error>
Sourcepub fn validate<'a, P: 'a + AsRef<Path>>(
&self,
path: P,
) -> Result<(), Vec<Error>>
pub fn validate<'a, P: 'a + AsRef<Path>>( &self, path: P, ) -> Result<(), Vec<Error>>
checks if a folder matches the shape and returns list of errors if they don’t match the errors specify why and where they are not matching
§Meaning of Errors
- NotFound if any file or folder doesn’t exist
- Interrupted if operation interrupts (aka been stooped)
- InvalidFile if a file that doesn’t match the pattern in a pattern dir was found
- InvalidFolder if a folder was found in a pattern dir
- PermissionDenied if the os refuses to give the program permission to read form disk any other error that’s not listed is IMPOSSIBLE to occur
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Shape<T>where
T: Freeze,
impl<T> RefUnwindSafe for Shape<T>where
T: RefUnwindSafe,
impl<T> Send for Shape<T>where
T: Send,
impl<T> Sync for Shape<T>where
T: Sync,
impl<T> Unpin for Shape<T>where
T: Unpin,
impl<T> UnwindSafe for Shape<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more