Struct radicle_surf::fs::Directory

source ·
pub struct Directory { /* private fields */ }
Expand description

A Directory is the representation of a file system directory, for a given git tree.

The name of a directory can be retrieved via File::name.

The Entries of a directory can be retrieved via Directory::entries.

Implementations§

source§

impl Directory

source

pub fn name(&self) -> &String

Get the name of the current Directory.

Examples found in repository?
examples/browsing.rs (line 53)
51
52
53
54
55
56
57
58
59
60
61
fn print_directory(d: &Directory, repo: &Repository, indent_level: usize) {
    let indent = " ".repeat(indent_level * 4);
    println!("{}{}/", &indent, d.name());
    for entry in d.entries(repo).unwrap() {
        match entry {
            fs::Entry::File(f) => println!("    {}{}", &indent, f.name()),
            fs::Entry::Directory(d) => print_directory(&d, repo, indent_level + 1),
            fs::Entry::Submodule(s) => println!("    {}{}", &indent, s.name()),
        }
    }
}
source

pub fn id(&self) -> Oid

The object identifier of this [Directory].

source

pub fn path(&self) -> PathBuf

Return the exact path for this Directory, including the name of the directory itself.

The path is relative to the git repository root.

source

pub fn location(&self) -> &Path

Return the Path where this Directory is located, relative to the git repository root.

source

pub fn entries(&self, repo: &Repository) -> Result<Entries, Directory>

Return the Entries for this Directory’s Oid.

The resulting Entries will only resolve to this Directory’s entries. Any sub-directories will need to be resolved independently.

§Errors

This function will fail if it could not find the git tree for the Oid.

Examples found in repository?
examples/browsing.rs (line 54)
51
52
53
54
55
56
57
58
59
60
61
fn print_directory(d: &Directory, repo: &Repository, indent_level: usize) {
    let indent = " ".repeat(indent_level * 4);
    println!("{}{}/", &indent, d.name());
    for entry in d.entries(repo).unwrap() {
        match entry {
            fs::Entry::File(f) => println!("    {}{}", &indent, f.name()),
            fs::Entry::Directory(d) => print_directory(&d, repo, indent_level + 1),
            fs::Entry::Submodule(s) => println!("    {}{}", &indent, s.name()),
        }
    }
}
source

pub fn find_entry<P>( &self, path: &P, repo: &Repository, ) -> Result<Entry, Directory>
where P: AsRef<Path>,

Find the Entry found at a non-empty path, if it exists.

source

pub fn find_file<P>( &self, path: &P, repo: &Repository, ) -> Result<File, Directory>
where P: AsRef<Path>,

Find the Oid, for a File, found at path, if it exists.

source

pub fn find_directory<P>( &self, path: &P, repo: &Repository, ) -> Result<Self, Directory>
where P: AsRef<Path>,

Find the Directory found at path, if it exists.

If path is ROOT_DIR (i.e. an empty path), returns self.

source

pub fn size(&self, repo: &Repository) -> Result<usize, Directory>

Get the total size, in bytes, of a Directory. The size is the sum of all files that can be reached from this Directory.

source

pub fn traverse<Error, B, F>( &self, repo: &Repository, initial: B, f: &mut F, ) -> Result<B, Error>
where Error: From<Directory>, F: FnMut(B, &Entry) -> Result<B, Error>,

Traverse the entire Directory using the initial accumulator and the function f.

For each Entry::Directory this will recursively call Directory::traverse and obtain its Entries.

Error is the error type of the fallible function. B is the type of the accumulator. F is the fallible function that takes the accumulator and the next Entry, possibly providing the next accumulator value.

Trait Implementations§

source§

impl Clone for Directory

source§

fn clone(&self) -> Directory

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Directory

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq for Directory

source§

fn eq(&self, other: &Directory) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Revision for Directory

source§

type Error = Infallible

source§

fn object_id(&self, _repo: &Repository) -> Result<Oid, Self::Error>

Returns the object id of this revision in repo.
source§

impl Eq for Directory

source§

impl StructuralPartialEq for Directory

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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<R> ToCommit for R
where R: Revision,

source§

type Error = Error

source§

fn to_commit(self, repo: &Repository) -> Result<Commit, <R as ToCommit>::Error>

Converts to a commit in repo.
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.