Skip to main content

ObjectTrait

Trait ObjectTrait 

Source
pub trait ObjectTrait:
    Send
    + Sync
    + Display {
    // Required methods
    fn from_bytes(data: &[u8], hash: ObjectHash) -> Result<Self, GitError>
       where Self: Sized;
    fn get_type(&self) -> ObjectType;
    fn get_size(&self) -> usize;
    fn to_data(&self) -> Result<Vec<u8>, GitError>;

    // Provided methods
    fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Self
       where Self: Sized { ... }
    fn object_hash(&self) -> Result<ObjectHash, GitError> { ... }
}
Expand description

The Object Trait Defines the common interface for all Git object types, including blobs, trees, commits, and tags.

Required Methods§

Source

fn from_bytes(data: &[u8], hash: ObjectHash) -> Result<Self, GitError>
where Self: Sized,

Creates a new object from a byte slice.

Source

fn get_type(&self) -> ObjectType

Returns the type of the object.

Source

fn get_size(&self) -> usize

Source

fn to_data(&self) -> Result<Vec<u8>, GitError>

Provided Methods§

Source

fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Self
where Self: Sized,

Generate a new Object from a ReadBoxed<BufRead>. the input size,is only for new a vec with directive space allocation the input data stream and output object should be plain base object .

Source

fn object_hash(&self) -> Result<ObjectHash, GitError>

Computes the object hash from serialized data.

Default implementation serializes the object and computes the hash from that data. Override only if you need custom hash computation or caching.

Implementors§