Struct git2::Tree

source ·
pub struct Tree<'repo> { /* private fields */ }
Expand description

A structure to represent a git tree

Implementations§

source§

impl<'repo> Tree<'repo>

source

pub fn id(&self) -> Oid

Get the id (SHA1) of a repository object

source

pub fn len(&self) -> usize

Get the number of entries listed in this tree.

source

pub fn is_empty(&self) -> bool

Return true if there is not entry

source

pub fn iter(&self) -> TreeIter<'_>

Returns an iterator over the entries in this tree.

source

pub fn walk<C, T>(&self, mode: TreeWalkMode, callback: C) -> Result<(), Error>
where C: FnMut(&str, &TreeEntry<'_>) -> T, T: Into<i32>,

Traverse the entries in a tree and its subtrees in post or pre-order. The callback function will be run on each node of the tree that’s walked. The return code of this function will determine how the walk continues.

libgit2 requires that the callback be an integer, where 0 indicates a successful visit, 1 skips the node, and -1 aborts the traversal completely. You may opt to use the enum TreeWalkResult instead.

let mut ct = 0;
tree.walk(TreeWalkMode::PreOrder, |_, entry| {
    assert_eq!(entry.name(), Some("foo"));
    ct += 1;
    TreeWalkResult::Ok
}).unwrap();
assert_eq!(ct, 1);

See libgit2 documentation for more information.

source

pub fn get_id(&self, id: Oid) -> Option<TreeEntry<'_>>

Lookup a tree entry by SHA value.

source

pub fn get(&self, n: usize) -> Option<TreeEntry<'_>>

Lookup a tree entry by its position in the tree

source

pub fn get_name(&self, filename: &str) -> Option<TreeEntry<'_>>

Lookup a tree entry by its filename

source

pub fn get_name_bytes(&self, filename: &[u8]) -> Option<TreeEntry<'_>>

Lookup a tree entry by its filename, specified as bytes.

This allows for non-UTF-8 filenames.

source

pub fn get_path(&self, path: &Path) -> Result<TreeEntry<'static>, Error>

Retrieve a tree entry contained in a tree or in any of its subtrees, given its relative path.

source

pub fn as_object(&self) -> &Object<'repo>

Casts this Tree to be usable as an Object

source

pub fn into_object(self) -> Object<'repo>

Consumes this Tree to be returned as an Object

Trait Implementations§

source§

impl<'repo> Clone for Tree<'repo>

source§

fn clone(&self) -> Self

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<'repo> Debug for Tree<'repo>

source§

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

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

impl<'repo> Drop for Tree<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'repo, 'iter> IntoIterator for &'iter Tree<'repo>

§

type Item = TreeEntry<'iter>

The type of the elements being iterated over.
§

type IntoIter = TreeIter<'iter>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'repo> Freeze for Tree<'repo>

§

impl<'repo> RefUnwindSafe for Tree<'repo>

§

impl<'repo> !Send for Tree<'repo>

§

impl<'repo> !Sync for Tree<'repo>

§

impl<'repo> Unpin for Tree<'repo>

§

impl<'repo> UnwindSafe for Tree<'repo>

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

§

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

§

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

§

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<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T