[][src]Struct radicle_surf::file_system::Directory

pub struct Directory {
    pub name: Label,
    pub entries: NonEmpty<DirectoryContents>,
}

A Directory consists of its Label and its entries. The entries are a set of DirectoryContents and there should be at least one entry. This is because empty directories do not generally exist in VCSes.

Fields

name: Labelentries: NonEmpty<DirectoryContents>

Methods

impl Directory[src]

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, DirectoryContents, File, Label};
use radicle_surf::file_system::unsound;

let files = (
    DirectoryContents::file(unsound::label::new("main.rs"), b"println!(\"Hello, world!\")"),
    vec![DirectoryContents::file(unsound::label::new("lib.rs"), b"struct Hello(String)")],
).into();

let directory = Directory {
    name: Label::root(),
    entries: files,
};

assert_eq!(directory.size(), 45);
use nonempty::NonEmpty;
use radicle_surf::file_system::{Directory, DirectoryContents, File, Label};
use radicle_surf::file_system::unsound;

let mut entries: NonEmpty<DirectoryContents> = (
    DirectoryContents::file(unsound::label::new("main.rs"), b"println!(\"Hello, world!\")"),
    vec![DirectoryContents::file(unsound::label::new("lib.rs"), b"struct Hello(String)")],
).into();

let subdir = DirectoryContents::sub_directory(Directory {
    name: unsound::label::new("test"),
    entries: NonEmpty::new(DirectoryContents::file(
        unsound::label::new("mod.rs"),
        b"assert_eq!(1 + 1, 2);",
    )),
});

entries.push(subdir);

let directory = Directory {
    name: Label::root(),
    entries: entries,
};

assert_eq!(directory.size(), 66);

pub fn list_directory(&self) -> Vec<(Label, SystemType)>[src]

List the current Directory's files and sub-directories.

pub fn find_file(&self, path: &Path) -> Option<File>[src]

Find a File in the directory given the Path to the File.

This operation fails if the path does not lead to the File.

pub fn find_directory(&self, path: &Path) -> Option<Self>[src]

Find a Directory in the directory given the Path to the Directory.

This operation fails if the path does not lead to the Directory.

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

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.