git_internal/internal/object/
mod.rs1pub mod blob;
4pub mod commit;
5pub mod context;
6pub mod decision;
7pub mod evidence;
8pub mod integrity;
9pub mod note;
10pub mod patchset;
11pub mod plan;
12pub mod provenance;
13pub mod run;
14pub mod signature;
15pub mod tag;
16pub mod task;
17pub mod tool;
18pub mod tree;
19pub mod types;
20pub mod utils;
21
22use std::{
23 fmt::Display,
24 io::{BufRead, Read},
25};
26
27use crate::{
28 errors::GitError,
29 hash::ObjectHash,
30 internal::{object::types::ObjectType, zlib::stream::inflate::ReadBoxed},
31};
32
33pub trait ObjectTrait: Send + Sync + Display {
36 fn from_bytes(data: &[u8], hash: ObjectHash) -> Result<Self, GitError>
38 where
39 Self: Sized;
40
41 fn from_buf_read<R: BufRead>(read: &mut ReadBoxed<R>, size: usize) -> Self
45 where
46 Self: Sized,
47 {
48 let mut content: Vec<u8> = Vec::with_capacity(size);
49 read.read_to_end(&mut content).unwrap();
50 let digest = read.hash.clone().finalize();
51 let hash = ObjectHash::from_bytes(&digest).unwrap();
52 Self::from_bytes(&content, hash).unwrap()
53 }
54
55 fn get_type(&self) -> ObjectType;
57
58 fn get_size(&self) -> usize;
59
60 fn to_data(&self) -> Result<Vec<u8>, GitError>;
61}