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