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:
ObjectTrait::from_buf_read_with_kind— load an object from aReadBoxedcreated for that kind and fail closed if the reader’s hasher belongs to another kind;ObjectTrait::object_hash_for_kind— compute the canonical object ID for an explicit kind.
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§
Sourcefn from_bytes(data: &[u8], hash: ObjectHash) -> Result<Self, GitError>where
Self: Sized,
fn from_bytes(data: &[u8], hash: ObjectHash) -> Result<Self, GitError>where
Self: Sized,
Creates a new object from a byte slice.
Sourcefn get_type(&self) -> ObjectType
fn get_type(&self) -> ObjectType
Returns the type of the object.
fn get_size(&self) -> usize
fn to_data(&self) -> Result<Vec<u8>, GitError>
Provided Methods§
Sourcefn 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_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.
Sourcefn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Selfwhere
Self: Sized,
fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Selfwhere
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.
Sourcefn object_hash_for_kind(&self, kind: HashKind) -> Result<ObjectHash, GitError>
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.
Sourcefn object_hash(&self) -> Result<ObjectHash, GitError>
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".