Struct git2::Object

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

A structure to represent a git object

Implementations§

source§

impl<'repo> Object<'repo>

source

pub fn id(&self) -> Oid

Get the id (SHA1) of a repository object

source

pub fn kind(&self) -> Option<ObjectType>

Get the object type of an object.

If the type is unknown, then None is returned.

source

pub fn peel(&self, kind: ObjectType) -> Result<Object<'repo>, Error>

Recursively peel an object until an object of the specified type is met.

If you pass Any as the target type, then the object will be peeled until the type changes (e.g. a tag will be chased until the referenced object is no longer a tag).

source

pub fn peel_to_blob(&self) -> Result<Blob<'repo>, Error>

Recursively peel an object until a blob is found

source

pub fn peel_to_commit(&self) -> Result<Commit<'repo>, Error>

Recursively peel an object until a commit is found

source

pub fn peel_to_tag(&self) -> Result<Tag<'repo>, Error>

Recursively peel an object until a tag is found

source

pub fn peel_to_tree(&self) -> Result<Tree<'repo>, Error>

Recursively peel an object until a tree is found

source

pub fn short_id(&self) -> Result<Buf, Error>

Get a short abbreviated OID string for the object

This starts at the “core.abbrev” length (default 7 characters) and iteratively extends to a longer string if that length is ambiguous. The result will be unambiguous (at least until new objects are added to the repository).

source

pub fn as_commit(&self) -> Option<&Commit<'repo>>

Attempt to view this object as a commit.

Returns None if the object is not actually a commit.

source

pub fn into_commit(self) -> Result<Commit<'repo>, Object<'repo>>

Attempt to consume this object and return a commit.

Returns Err(self) if this object is not actually a commit.

source

pub fn as_tag(&self) -> Option<&Tag<'repo>>

Attempt to view this object as a tag.

Returns None if the object is not actually a tag.

source

pub fn into_tag(self) -> Result<Tag<'repo>, Object<'repo>>

Attempt to consume this object and return a tag.

Returns Err(self) if this object is not actually a tag.

source

pub fn as_tree(&self) -> Option<&Tree<'repo>>

Attempt to view this object as a tree.

Returns None if the object is not actually a tree.

source

pub fn into_tree(self) -> Result<Tree<'repo>, Object<'repo>>

Attempt to consume this object and return a tree.

Returns Err(self) if this object is not actually a tree.

source

pub fn as_blob(&self) -> Option<&Blob<'repo>>

Attempt to view this object as a blob.

Returns None if the object is not actually a blob.

source

pub fn into_blob(self) -> Result<Blob<'repo>, Object<'repo>>

Attempt to consume this object and return a blob.

Returns Err(self) if this object is not actually a blob.

source

pub fn describe(&self, opts: &DescribeOptions) -> Result<Describe<'_>, Error>

Describes a commit

Performs a describe operation on this commitish object.

Trait Implementations§

source§

impl<'repo> Clone for Object<'repo>

source§

fn clone(&self) -> Object<'repo>

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 Object<'repo>

source§

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

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

impl<'repo> Drop for Object<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'repo> RefUnwindSafe for Object<'repo>

§

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

§

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

§

impl<'repo> Unpin for Object<'repo>

§

impl<'repo> UnwindSafe for Object<'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.