summaryrefslogtreecommitdiffstats
path: root/vendor/gix-odb/src/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-odb/src/traits.rs')
-rw-r--r--vendor/gix-odb/src/traits.rs104
1 files changed, 35 insertions, 69 deletions
diff --git a/vendor/gix-odb/src/traits.rs b/vendor/gix-odb/src/traits.rs
index ddec78b8e..91d66c42d 100644
--- a/vendor/gix-odb/src/traits.rs
+++ b/vendor/gix-odb/src/traits.rs
@@ -4,21 +4,16 @@ use gix_object::WriteTo;
/// Describe the capability to write git objects into an object store.
pub trait Write {
- /// The error type used for all trait methods.
- ///
- /// _Note_ the default implementations require the `From<io::Error>` bound.
- type Error: std::error::Error + From<io::Error>;
-
/// Write objects using the intrinsic kind of [`hash`][gix_hash::Kind] into the database,
/// returning id to reference it in subsequent reads.
- fn write(&self, object: impl WriteTo) -> Result<gix_hash::ObjectId, Self::Error> {
+ fn write(&self, object: &dyn WriteTo) -> Result<gix_hash::ObjectId, crate::write::Error> {
let mut buf = Vec::with_capacity(2048);
object.write_to(&mut buf)?;
- self.write_stream(object.kind(), buf.len() as u64, buf.as_slice())
+ self.write_stream(object.kind(), buf.len() as u64, &mut buf.as_slice())
}
/// As [`write`][Write::write], but takes an [`object` kind][gix_object::Kind] along with its encoded bytes.
- fn write_buf(&self, object: gix_object::Kind, from: &[u8]) -> Result<gix_hash::ObjectId, Self::Error> {
- self.write_stream(object, from.len() as u64, from)
+ fn write_buf(&self, object: gix_object::Kind, mut from: &[u8]) -> Result<gix_hash::ObjectId, crate::write::Error> {
+ self.write_stream(object, from.len() as u64, &mut from)
}
/// As [`write`][Write::write], but takes an input stream.
/// This is commonly used for writing blobs directly without reading them to memory first.
@@ -26,8 +21,8 @@ pub trait Write {
&self,
kind: gix_object::Kind,
size: u64,
- from: impl io::Read,
- ) -> Result<gix_hash::ObjectId, Self::Error>;
+ from: &mut dyn io::Read,
+ ) -> Result<gix_hash::ObjectId, crate::write::Error>;
}
/// Describe how object can be located in an object store.
@@ -39,11 +34,8 @@ pub trait Write {
///
/// [issue]: https://github.com/rust-lang/rust/issues/44265
pub trait Find {
- /// The error returned by [`try_find()`][Find::try_find()]
- type Error: std::error::Error + 'static;
-
/// Returns true if the object exists in the database.
- fn contains(&self, id: impl AsRef<gix_hash::oid>) -> bool;
+ fn contains(&self, id: &gix_hash::oid) -> bool;
/// Find an object matching `id` in the database while placing its raw, possibly encoded data into `buffer`.
///
@@ -51,17 +43,15 @@ pub trait Find {
/// retrieval.
fn try_find<'a>(
&self,
- id: impl AsRef<gix_hash::oid>,
+ id: &gix_hash::oid,
buffer: &'a mut Vec<u8>,
- ) -> Result<Option<gix_object::Data<'a>>, Self::Error>;
+ ) -> Result<Option<gix_object::Data<'a>>, find::Error>;
}
/// A way to obtain object properties without fully decoding it.
pub trait Header {
- /// The error returned by [`try_header()`][Header::try_header()].
- type Error: std::error::Error + 'static;
/// Try to read the header of the object associated with `id` or return `None` if it could not be found.
- fn try_header(&self, id: impl AsRef<gix_hash::oid>) -> Result<Option<find::Header>, Self::Error>;
+ fn try_header(&self, id: &gix_hash::oid) -> Result<Option<find::Header>, find::Error>;
}
mod _impls {
@@ -76,17 +66,15 @@ mod _impls {
where
T: crate::Write,
{
- type Error = T::Error;
-
- fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
+ fn write(&self, object: &dyn WriteTo) -> Result<ObjectId, crate::write::Error> {
(*self).write(object)
}
- fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
+ fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, crate::write::Error> {
(*self).write_buf(object, from)
}
- fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
+ fn write_stream(&self, kind: Kind, size: u64, from: &mut dyn Read) -> Result<ObjectId, crate::write::Error> {
(*self).write_stream(kind, size, from)
}
}
@@ -95,17 +83,15 @@ mod _impls {
where
T: crate::Write,
{
- type Error = T::Error;
-
- fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
+ fn write(&self, object: &dyn WriteTo) -> Result<ObjectId, crate::write::Error> {
self.deref().write(object)
}
- fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
+ fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, crate::write::Error> {
self.deref().write_buf(object, from)
}
- fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
+ fn write_stream(&self, kind: Kind, size: u64, from: &mut dyn Read) -> Result<ObjectId, crate::write::Error> {
self.deref().write_stream(kind, size, from)
}
}
@@ -114,17 +100,15 @@ mod _impls {
where
T: crate::Write,
{
- type Error = T::Error;
-
- fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error> {
+ fn write(&self, object: &dyn WriteTo) -> Result<ObjectId, crate::write::Error> {
self.deref().write(object)
}
- fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, Self::Error> {
+ fn write_buf(&self, object: Kind, from: &[u8]) -> Result<ObjectId, crate::write::Error> {
self.deref().write_buf(object, from)
}
- fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
+ fn write_stream(&self, kind: Kind, size: u64, from: &mut dyn Read) -> Result<ObjectId, crate::write::Error> {
self.deref().write_stream(kind, size, from)
}
}
@@ -133,13 +117,11 @@ mod _impls {
where
T: crate::Find,
{
- type Error = T::Error;
-
- fn contains(&self, id: impl AsRef<oid>) -> bool {
+ fn contains(&self, id: &oid) -> bool {
(*self).contains(id)
}
- fn try_find<'a>(&self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, Self::Error> {
+ fn try_find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, crate::find::Error> {
(*self).try_find(id, buffer)
}
}
@@ -148,9 +130,7 @@ mod _impls {
where
T: crate::Header,
{
- type Error = T::Error;
-
- fn try_header(&self, id: impl AsRef<oid>) -> Result<Option<Header>, Self::Error> {
+ fn try_header(&self, id: &oid) -> Result<Option<Header>, crate::find::Error> {
(*self).try_header(id)
}
}
@@ -159,13 +139,11 @@ mod _impls {
where
T: crate::Find,
{
- type Error = T::Error;
-
- fn contains(&self, id: impl AsRef<oid>) -> bool {
+ fn contains(&self, id: &oid) -> bool {
self.deref().contains(id)
}
- fn try_find<'a>(&self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, Self::Error> {
+ fn try_find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, crate::find::Error> {
self.deref().try_find(id, buffer)
}
}
@@ -174,9 +152,7 @@ mod _impls {
where
T: crate::Header,
{
- type Error = T::Error;
-
- fn try_header(&self, id: impl AsRef<oid>) -> Result<Option<Header>, Self::Error> {
+ fn try_header(&self, id: &oid) -> Result<Option<Header>, crate::find::Error> {
self.deref().try_header(id)
}
}
@@ -185,13 +161,11 @@ mod _impls {
where
T: crate::Find,
{
- type Error = T::Error;
-
- fn contains(&self, id: impl AsRef<oid>) -> bool {
+ fn contains(&self, id: &oid) -> bool {
self.deref().contains(id)
}
- fn try_find<'a>(&self, id: impl AsRef<oid>, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, Self::Error> {
+ fn try_find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Option<Data<'a>>, crate::find::Error> {
self.deref().try_find(id, buffer)
}
}
@@ -200,9 +174,7 @@ mod _impls {
where
T: crate::Header,
{
- type Error = T::Error;
-
- fn try_header(&self, id: impl AsRef<oid>) -> Result<Option<Header>, Self::Error> {
+ fn try_header(&self, id: &oid) -> Result<Option<Header>, crate::find::Error> {
self.deref().try_header(id)
}
}
@@ -219,10 +191,9 @@ mod ext {
/// while returning the desired object type.
fn $method<'a>(
&self,
- id: impl AsRef<gix_hash::oid>,
+ id: &gix_hash::oid,
buffer: &'a mut Vec<u8>,
- ) -> Result<$object_type, find::existing_object::Error<Self::Error>> {
- let id = id.as_ref();
+ ) -> Result<$object_type, find::existing_object::Error> {
self.try_find(id, buffer)
.map_err(find::existing_object::Error::Find)?
.ok_or_else(|| find::existing_object::Error::NotFound {
@@ -245,10 +216,9 @@ mod ext {
/// while returning the desired iterator type.
fn $method<'a>(
&self,
- id: impl AsRef<gix_hash::oid>,
+ id: &gix_hash::oid,
buffer: &'a mut Vec<u8>,
- ) -> Result<$object_type, find::existing_iter::Error<Self::Error>> {
- let id = id.as_ref();
+ ) -> Result<$object_type, find::existing_iter::Error> {
self.try_find(id, buffer)
.map_err(find::existing_iter::Error::Find)?
.ok_or_else(|| find::existing_iter::Error::NotFound {
@@ -267,10 +237,7 @@ mod ext {
/// An extension trait with convenience functions.
pub trait HeaderExt: super::Header {
/// Like [`try_header(…)`][super::Header::try_header()], but flattens the `Result<Option<_>>` into a single `Result` making a non-existing object an error.
- fn header(
- &self,
- id: impl AsRef<gix_hash::oid>,
- ) -> Result<crate::find::Header, find::existing::Error<Self::Error>> {
+ fn header(&self, id: impl AsRef<gix_hash::oid>) -> Result<find::Header, find::existing::Error> {
let id = id.as_ref();
self.try_header(id)
.map_err(find::existing::Error::Find)?
@@ -285,10 +252,9 @@ mod ext {
/// Like [`try_find(…)`][super::Find::try_find()], but flattens the `Result<Option<_>>` into a single `Result` making a non-existing object an error.
fn find<'a>(
&self,
- id: impl AsRef<gix_hash::oid>,
+ id: &gix_hash::oid,
buffer: &'a mut Vec<u8>,
- ) -> Result<gix_object::Data<'a>, find::existing::Error<Self::Error>> {
- let id = id.as_ref();
+ ) -> Result<gix_object::Data<'a>, find::existing::Error> {
self.try_find(id, buffer)
.map_err(find::existing::Error::Find)?
.ok_or_else(|| find::existing::Error::NotFound { oid: id.to_owned() })