1use std::ops::DerefMut;
2
3use gix_object::Kind;
4
5pub trait DecodeEntry {
9 fn put(&mut self, pack_id: u32, offset: u64, data: &[u8], kind: gix_object::Kind, compressed_size: usize);
13 fn get(&mut self, pack_id: u32, offset: u64, out: &mut Vec<u8>) -> Option<(gix_object::Kind, usize)>;
16}
17
18#[derive(Default)]
20pub struct Never;
21
22impl DecodeEntry for Never {
23 fn put(&mut self, _pack_id: u32, _offset: u64, _data: &[u8], _kind: gix_object::Kind, _compressed_size: usize) {}
24 fn get(&mut self, _pack_id: u32, _offset: u64, _out: &mut Vec<u8>) -> Option<(gix_object::Kind, usize)> {
25 None
26 }
27}
28
29impl<T: DecodeEntry + ?Sized> DecodeEntry for Box<T> {
30 fn put(&mut self, pack_id: u32, offset: u64, data: &[u8], kind: Kind, compressed_size: usize) {
31 self.deref_mut().put(pack_id, offset, data, kind, compressed_size);
32 }
33
34 fn get(&mut self, pack_id: u32, offset: u64, out: &mut Vec<u8>) -> Option<(Kind, usize)> {
35 self.deref_mut().get(pack_id, offset, out)
36 }
37}
38
39pub trait Object {
41 fn put(&mut self, id: gix_hash::ObjectId, kind: gix_object::Kind, data: &[u8]);
43
44 fn get(&mut self, id: &gix_hash::ObjectId, out: &mut Vec<u8>) -> Option<gix_object::Kind>;
46}
47
48#[cfg(any(feature = "pack-cache-lru-dynamic", feature = "pack-cache-lru-static"))]
50pub mod lru;
51
52pub mod object;
53
54pub(crate) mod delta;
56
57#[cfg(any(
61 feature = "pack-cache-lru-static",
62 feature = "pack-cache-lru-dynamic",
63 feature = "object-cache-dynamic"
64))]
65fn set_vec_to_slice<V: std::borrow::BorrowMut<Vec<u8>>>(mut vec: V, source: &[u8]) -> Option<V> {
66 let out = vec.borrow_mut();
67 out.clear();
68 out.try_reserve(source.len()).ok()?;
69 out.extend_from_slice(source);
70 Some(vec)
71}