Shape

Struct Shape 

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

Source

pub fn new() -> Self

creates a new shape

Source

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

create the shape in a directory

Source

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

Source

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§

Source§

impl<T: ShapeDescribe> Debug for Shape<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.
Source§

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

Source§

fn vzip(self) -> V