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_with_kind<R: BufRead>(
        read: &mut ReadBoxed<R>,
        size: usize,
        kind: HashKind,
    ) -> Result<Self, GitError>
       where Self: Sized { ... }
    fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Self
       where Self: Sized { ... }
    fn object_hash_for_kind(
        &self,
        kind: HashKind,
    ) -> Result<ObjectHash, GitError> { ... }
    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.

§Repository hash context

Object IDs depend on the repository’s HashKind. Every implementor (standard Git objects and AI objects alike) gets two explicit-kind entry points for free from the default methods:

The parameterless ObjectTrait::from_buf_read and ObjectTrait::object_hash keep the thread-local behaviour for the established single-repository workflow (GC-06); code that may run on a thread configured for another repository must pass the kind explicitly.

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_with_kind<R: BufRead>( read: &mut ReadBoxed<R>, size: usize, kind: HashKind, ) -> Result<Self, GitError>
where Self: Sized,

Generate a new Object from a ReadBoxed<BufRead> whose hasher was created for kind (see ReadBoxed::new_with_kind).

size is only a capacity hint for the content buffer. The object ID is finalized from the reader’s own hasher; if that hasher belongs to a different HashKind than kind, the call fails closed with a HashError::KindMismatch wrapped in GitError::InvalidHashValue instead of mislabelling the digest.

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 .

Compatibility wrapper around ObjectTrait::from_buf_read_with_kind using the thread-local HashKind. It keeps the pre-existing contract of this signature: any failure (I/O, parse, or a reader whose hasher does not match the thread-local kind — formerly an “Invalid byte length” panic) is a panic. New code should call the explicit-kind variant and handle the error.

Source

fn object_hash_for_kind(&self, kind: HashKind) -> Result<ObjectHash, GitError>

Canonical object ID of this object for an explicit repository kind.

Does not consult the thread-local HashKind.

Source

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

Canonical object ID of this object using the thread-local HashKind.

Compatibility wrapper around ObjectTrait::object_hash_for_kind.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§