[][src]Struct fs_pro::shape::Shape

pub struct Shape<T: ShapeDescribe> { /* fields omitted */ }

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

impl<T: ShapeDescribe> Shape<T>[src]

pub fn new() -> Self[src]

creates a new shape

pub fn create_at<'a, P: 'a + AsRef<Path>>(&self, path: P) -> Result<T, Error>[src]

create the shape in a directory

pub fn create_at_hook<'a, P: 'a + AsRef<Path>>(
    &self,
    path: P,
    hook: &'a dyn Fn(PathBuf, bool)
) -> Result<T, Error>
[src]

pub fn validate<'a, P: 'a + AsRef<Path>>(
    &self,
    path: P
) -> Result<(), Vec<Error>>
[src]

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

impl<T: ShapeDescribe> Debug for Shape<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Shape<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Shape<T> where
    T: Send
[src]

impl<T> Sync for Shape<T> where
    T: Sync
[src]

impl<T> Unpin for Shape<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Shape<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,