[−][src]Struct radicle_surf::file_system::directory::Directory
A Directory
can be thought of as a non-empty set of entries of
sub-directories and files. The reason for the non-empty property is that a
VCS directory would have at least one artifact as a sub-directory which
tracks the VCS work, e.g. git using the .git
folder.
On top of that, some VCSes, such as git, will not track an empty directory, and so when creating a new directory to track it will have to contain at least one file.
Implementations
impl Directory
[src]
pub fn root() -> Self
[src]
Create a root directory.
This function is usually used for testing and demonstation purposes.
pub fn new(label: Label) -> Self
[src]
Create a directory, similar to root
, except with a given name.
This function is usually used for testing and demonstation purposes.
pub fn list_directory(&self) -> Vec<(Label, SystemType)>
[src]
List the current Directory
's files and sub-directories.
The listings are a pair of Label
and SystemType
, where the
Label
represents the name of the file or directory.
use nonempty::NonEmpty; use radicle_surf::file_system::{Directory, File, SystemType}; use radicle_surf::file_system::unsound; let mut directory = Directory::root(); // Root files set up let root_files = NonEmpty::from(( (unsound::label::new("foo.rs"), File::new(b"use crate::bar")), vec![( unsound::label::new("bar.rs"), File::new(b"fn hello_world()"), )], )); directory.insert_files(&[], root_files); // Haskell files set up let haskell_files = NonEmpty::from(( ( unsound::label::new("foo.hs"), File::new(b"module Foo where"), ), vec![( unsound::label::new("bar.hs"), File::new(b"module Bar where"), )], )); directory.insert_files(&[unsound::label::new("haskell")], haskell_files); let mut directory_contents = directory.list_directory(); directory_contents.sort(); assert_eq!( directory_contents, vec![ SystemType::file(unsound::label::new("bar.rs")), SystemType::file(unsound::label::new("foo.rs")), SystemType::directory(unsound::label::new("haskell")), ] );
pub fn iter(&self) -> impl Iterator<Item = DirectoryContents> + '_
[src]
Get the Label
of the current directory.
Examples
use radicle_surf::file_system::{Directory, DirectoryContents, File, Label}; use radicle_surf::file_system::unsound; let mut root = Directory::root(); let main = File::new(b"println!(\"Hello, world!\")"); root.insert_file(unsound::path::new("main.rs"), main.clone()); let lib = File::new(b"struct Hello(String)"); root.insert_file(unsound::path::new("lib.rs"), lib.clone()); let test_mod = File::new(b"assert_eq!(1 + 1, 2);"); root.insert_file(unsound::path::new("test/mod.rs"), test_mod.clone()); let mut root_iter = root.iter(); assert_eq!(root_iter.next(), Some(DirectoryContents::File { name: unsound::label::new("lib.rs"), file: lib })); assert_eq!(root_iter.next(), Some(DirectoryContents::File { name: unsound::label::new("main.rs"), file: main })); let mut test_dir = Directory::new(unsound::label::new("test")); test_dir.insert_file(unsound::path::new("mod.rs"), test_mod); assert_eq!(root_iter.next(), Some(DirectoryContents::Directory(test_dir)));
pub fn find_file(&self, path: Path) -> Option<File>
[src]
Find a File
in the directory given the Path
to the File
.
Failures
This operation fails if the path does not lead to a File
.
If the search is for a Directory
then use find_directory
.
Examples
Search for a file in the path:
* foo/bar/baz.hs
* foo
* foo/bar/qux.rs
use radicle_surf::file_system::{Directory, File}; use radicle_surf::file_system::unsound; let file = File::new(b"module Banana ..."); let mut directory = Directory::root(); directory.insert_file(unsound::path::new("foo/bar/baz.rs"), file.clone()); // The file is succesfully found assert_eq!(directory.find_file(unsound::path::new("foo/bar/baz.rs")), Some(file)); // We shouldn't be able to find a directory assert_eq!(directory.find_file(unsound::path::new("foo")), None); // We shouldn't be able to find a file that doesn't exist assert_eq!(directory.find_file(unsound::path::new("foo/bar/qux.rs")), None);
pub fn find_directory(&self, path: Path) -> Option<Self>
[src]
Find a Directory
in the directory given the Path
to the
Directory
.
Failures
This operation fails if the path does not lead to the Directory
.
Examples
Search for directories in the path:
* foo
* foo/bar
* foo/baz
use radicle_surf::file_system::{Directory, File}; use radicle_surf::file_system::unsound; let file = File::new(b"module Banana ..."); let mut directory = Directory::root(); directory.insert_file(unsound::path::new("foo/bar/baz.rs"), file.clone()); // Can find the first level assert!(directory.find_directory(unsound::path::new("foo")).is_some()); // Can find the second level assert!(directory.find_directory(unsound::path::new("foo/bar")).is_some()); // Cannot find 'baz' since it does not exist assert!(directory.find_directory(unsound::path::new("foo/baz")).is_none()); // 'baz.rs' is a file and not a directory assert!(directory.find_directory(unsound::path::new("foo/bar/baz.rs")).is_none());
pub fn current(&self) -> Label
[src]
Get the Label
of the current directory.
Examples
use radicle_surf::file_system::{Directory, File, Label}; use radicle_surf::file_system::unsound; let mut root = Directory::root(); root.insert_file(unsound::path::new("main.rs"), File::new(b"println!(\"Hello, world!\")")); root.insert_file(unsound::path::new("lib.rs"), File::new(b"struct Hello(String)")); root.insert_file(unsound::path::new("test/mod.rs"), File::new(b"assert_eq!(1 + 1, 2);")); assert_eq!(root.current(), Label::root()); let test = root.find_directory( unsound::path::new("test") ).expect("Missing test directory"); assert_eq!(test.current(), unsound::label::new("test"));
pub fn size(&self) -> usize
[src]
Get the total size, in bytes, of a Directory
. The size is
the sum of all files that can be reached from this Directory
.
Examples
use radicle_surf::file_system::{Directory, File}; use radicle_surf::file_system::unsound; let mut root = Directory::root(); root.insert_file(unsound::path::new("main.rs"), File::new(b"println!(\"Hello, world!\")")); root.insert_file(unsound::path::new("lib.rs"), File::new(b"struct Hello(String)")); root.insert_file(unsound::path::new("test/mod.rs"), File::new(b"assert_eq!(1 + 1, 2);")); assert_eq!(root.size(), 66);
pub fn insert_file(&mut self, path: Path, file: File)
[src]
Insert a file into a directory, given the full path to file (file name
inclusive) and the File
itself.
This function is usually used for testing and demonstation purposes.
pub fn insert_files(
&mut self,
directory_path: &[Label],
files: NonEmpty<(Label, File)>
)
[src]
&mut self,
directory_path: &[Label],
files: NonEmpty<(Label, File)>
)
Insert files into a shared directory path.
directory_path
is used as the prefix to where the files should go. If
empty the files will be placed in the current Directory
.
files
are pairs of file name and the File
itself.
This function is usually used for testing and demonstation purposes.
Trait Implementations
impl Clone for Directory
[src]
impl Debug for Directory
[src]
impl Eq for Directory
[src]
impl PartialEq<Directory> for Directory
[src]
impl StructuralEq for Directory
[src]
impl StructuralPartialEq for Directory
[src]
Auto Trait Implementations
impl RefUnwindSafe for Directory
impl Send for Directory
impl Sync for Directory
impl Unpin for Directory
impl UnwindSafe for Directory
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Conv for T
impl<T> Conv for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Self: Binary,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Self: Display,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Self: LowerExp,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Self: LowerHex,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Self: Octal,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Self: Pointer,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Self: UpperExp,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Self: UpperHex,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pipe for T where
T: ?Sized,
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
B: 'a + ?Sized,
R: 'a,
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Self: Borrow<B>,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
B: 'a + ?Sized,
R: 'a,
Self: BorrowMut<B>,
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
B: 'a + ?Sized,
R: 'a,
Self: BorrowMut<B>,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
R: 'a,
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Self: AsRef<U>,
U: 'a + ?Sized,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
R: 'a,
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Self: AsMut<U>,
U: 'a + ?Sized,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
R: 'a,
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Self: Deref<Target = T>,
T: 'a + ?Sized,
fn pipe_deref_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: DerefMut<Target = T> + Deref,
T: 'a + ?Sized,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: DerefMut<Target = T> + Deref,
T: 'a + ?Sized,
impl<T> Pipe for T
impl<T> PipeAsRef for T
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
R: 'a,
Self: AsRef<T>,
T: 'a,
R: 'a,
Self: AsRef<T>,
T: 'a,
fn pipe_as_mut<'a, T, R>(&'a mut self, func: impl FnOnce(&'a mut T) -> R) -> R where
R: 'a,
Self: AsMut<T>,
T: 'a,
R: 'a,
Self: AsMut<T>,
T: 'a,
impl<T> PipeBorrow for T
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
R: 'a,
Self: Borrow<T>,
T: 'a,
R: 'a,
Self: Borrow<T>,
T: 'a,
fn pipe_borrow_mut<'a, T, R>(
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: BorrowMut<T>,
T: 'a,
&'a mut self,
func: impl FnOnce(&'a mut T) -> R
) -> R where
R: 'a,
Self: BorrowMut<T>,
T: 'a,
impl<T> PipeDeref for T
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
R: 'a,
Self: Deref,
R: 'a,
Self: Deref,
fn pipe_deref_mut<'a, R>(
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
R: 'a,
Self: DerefMut,
&'a mut self,
func: impl FnOnce(&'a mut Self::Target) -> R
) -> R where
R: 'a,
Self: DerefMut,
impl<T> PipeRef for T
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
R: 'a,
fn pipe_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
R: 'a,
impl<T> Tap for T
fn tap(self, func: impl FnOnce(&Self)) -> Self
fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
B: ?Sized,
Self: Borrow<B>,
B: ?Sized,
Self: Borrow<B>,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
B: ?Sized,
Self: BorrowMut<B>,
B: ?Sized,
Self: BorrowMut<B>,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
R: ?Sized,
Self: AsRef<R>,
R: ?Sized,
Self: AsRef<R>,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
R: ?Sized,
Self: AsMut<R>,
R: ?Sized,
Self: AsMut<R>,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
B: ?Sized,
Self: Borrow<B>,
B: ?Sized,
Self: Borrow<B>,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
B: ?Sized,
Self: BorrowMut<B>,
B: ?Sized,
Self: BorrowMut<B>,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
R: ?Sized,
Self: AsRef<R>,
R: ?Sized,
Self: AsRef<R>,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
R: ?Sized,
Self: AsMut<R>,
R: ?Sized,
Self: AsMut<R>,
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
impl<T> Tap for T
fn tap<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self) -> R,
F: FnOnce(&Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self) -> R,
F: FnOnce(&mut Self) -> R,
impl<T, U> TapAsRef<U> for T where
U: ?Sized,
U: ?Sized,
fn tap_ref<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
fn tap_ref_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: AsRef<T>,
F: FnOnce(&T) -> R,
Self: AsRef<T>,
fn tap_ref_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
fn tap_ref_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
F: FnOnce(&mut T) -> R,
Self: AsMut<T>,
impl<T, U> TapBorrow<U> for T where
U: ?Sized,
U: ?Sized,
fn tap_borrow<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
fn tap_borrow_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&T) -> R,
Self: Borrow<T>,
F: FnOnce(&T) -> R,
Self: Borrow<T>,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
fn tap_borrow_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Self: BorrowMut<T>,
impl<T> TapDeref for T
fn tap_deref<F, R>(self, func: F) -> Self where
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&Self::Target) -> R,
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Self: Deref,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
fn tap_deref_mut_dbg<F, R>(self, func: F) -> Self where
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Self: DerefMut,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> TryConv for T
impl<T> TryConv for T
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,