History

Implement `git_odb::Find` for `git_odb::Handle`

Sebastian Thiel committed 4 years ago

Commit 3522aef1 parent 15b83723 files · +22 −6Browse files

Unified · Split

3 files
  1. git-odb/src/cache.rs +3 −3
  2. git-odb/src/store_impls/dynamic/find.rs +18 −2
  3. git-odb/src/store_impls/linked/find.rs +1 −1
git-odb/src/cache.rs+3−3
@@ -124,7 +124,7 @@ mod impls { · 123 unmodified lines
124124
125125 impl<S> crate::Find for Cache<S>
126126 where
127− S: crate::pack::Find,
127+ S: git_pack::Find,
128128 {
129129 type Error = S::Error;
130130
@@ -137,9 +137,9 @@ mod impls { · 6 unmodified lines
137137 }
138138 }
139139
140− impl<S> crate::pack::Find for Cache<S>
140+ impl<S> git_pack::Find for Cache<S>
141141 where
142− S: crate::pack::Find,
142+ S: git_pack::Find,
143143 {
144144 type Error = S::Error;
145145
git-odb/src/store_impls/dynamic/find.rs+18−2
@@ -9,7 +9,7 @@ use crate::store::handle; · 8 unmodified lines
99 mod error {
1010 use crate::{loose, pack};
1111
12− /// Returned by [`Handle::try_find()`][crate::pack::Find::try_find()]
12+ /// Returned by [`Handle::try_find()`][git_pack::Find::try_find()]
1313 #[derive(thiserror::Error, Debug)]
1414 #[allow(missing_docs)]
1515 pub enum Error {
@@ -27,7 +27,7 @@ pub use error::Error; · 11 unmodified lines
2727
2828 use crate::store::types::PackId;
2929
30−impl<S> crate::pack::Find for super::Handle<S>
30+impl<S> git_pack::Find for super::Handle<S>
3131 where
3232 S: Deref<Target = super::Store> + Clone,
3333 {
@@ -304,3 +304,19 @@ where · 270 unmodified lines
304304 }
305305 }
306306 }
307+
308+impl<S> crate::Find for super::Handle<S>
309+where
310+ S: Deref<Target = super::Store> + Clone,
311+ Self: git_pack::Find,
312+{
313+ type Error = <Self as git_pack::Find>::Error;
314+
315+ fn contains(&self, id: impl AsRef<oid>) -> bool {
316+ git_pack::Find::contains(self, id)
317+ }
318+
319+ fn try_find<'a>(&self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, Self::Error> {
320+ git_pack::Find::try_find(self, id, buffer).map(|t| t.map(|t| t.0))
321+ }
322+}
git-odb/src/store_impls/linked/find.rs+1−1
@@ -9,7 +9,7 @@ use crate::{ · 8 unmodified lines
99 store_impls::{compound, linked},
1010 };
1111
12−impl crate::pack::Find for linked::Store {
12+impl git_pack::Find for linked::Store {
1313 type Error = compound::find::Error;
1414
1515 /// Return true if the given object `id` is contained in the store.