gix_object/
find.rs

1/// The error type returned by the [`Find`](crate::Find) trait.
2pub type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
3///
4pub mod existing {
5    use gix_hash::ObjectId;
6
7    /// The error returned by the [`find(…)`][crate::FindExt::find()] trait methods.
8    #[derive(Debug, thiserror::Error)]
9    #[allow(missing_docs)]
10    pub enum Error {
11        #[error(transparent)]
12        Find(crate::find::Error),
13        #[error("An object with id {} could not be found", .oid)]
14        NotFound { oid: ObjectId },
15    }
16}
17
18///
19pub mod existing_object {
20    use gix_hash::ObjectId;
21
22    /// The error returned by the various [`find_*()`][crate::FindExt::find_commit()] trait methods.
23    #[derive(Debug, thiserror::Error)]
24    #[allow(missing_docs)]
25    pub enum Error {
26        #[error(transparent)]
27        Find(crate::find::Error),
28        #[error("Could not decode object at {oid}")]
29        Decode {
30            oid: ObjectId,
31            source: crate::decode::Error,
32        },
33        #[error("An object with id {oid} could not be found")]
34        NotFound { oid: ObjectId },
35        #[error("Expected object of kind {expected} but got {actual} at {oid}")]
36        ObjectKind {
37            oid: ObjectId,
38            actual: crate::Kind,
39            expected: crate::Kind,
40        },
41    }
42}
43
44///
45pub mod existing_iter {
46    use gix_hash::ObjectId;
47
48    /// The error returned by the various [`find_*_iter()`][crate::FindExt::find_commit_iter()] trait methods.
49    #[derive(Debug, thiserror::Error)]
50    #[allow(missing_docs)]
51    pub enum Error {
52        #[error(transparent)]
53        Find(crate::find::Error),
54        #[error("An object with id {oid} could not be found")]
55        NotFound { oid: ObjectId },
56        #[error("Expected object of kind {expected} but got {actual} at {oid}")]
57        ObjectKind {
58            oid: ObjectId,
59            actual: crate::Kind,
60            expected: crate::Kind,
61        },
62    }
63}
64
65/// An implementation of all traits that never fails, but also never finds anything.
66#[derive(Debug, Copy, Clone)]
67pub struct Never;
68
69impl super::FindHeader for Never {
70    fn try_header(&self, _id: &gix_hash::oid) -> Result<Option<crate::Header>, Error> {
71        Ok(None)
72    }
73}
74
75impl super::Find for Never {
76    fn try_find<'a>(&self, _id: &gix_hash::oid, _buffer: &'a mut Vec<u8>) -> Result<Option<crate::Data<'a>>, Error> {
77        Ok(None)
78    }
79}
80
81impl super::Exists for Never {
82    fn exists(&self, _id: &gix_hash::oid) -> bool {
83        false
84    }
85}