gix_ref/store/general/handle/
find.rs

1use crate::{store, PartialNameRef, Reference};
2
3mod error {
4    use std::convert::Infallible;
5
6    /// The error returned by [`crate::file::Store::find_loose()`].
7    #[derive(Debug, thiserror::Error)]
8    #[allow(missing_docs)]
9    pub enum Error {
10        #[error("An error occurred while finding a reference in the loose file database")]
11        Loose(#[from] crate::file::find::Error),
12        #[error("The ref name or path is not a valid ref name")]
13        RefnameValidation(#[from] crate::name::Error),
14    }
15
16    impl From<Infallible> for Error {
17        fn from(_: Infallible) -> Self {
18            unreachable!("this impl is needed to allow passing a known valid partial path as parameter")
19        }
20    }
21}
22
23pub use error::Error;
24
25use crate::store::handle;
26
27impl store::Handle {
28    /// TODO: actually implement this with handling of the packed buffer.
29    pub fn try_find<'a, Name, E>(&self, partial: Name) -> Result<Option<Reference>, Error>
30    where
31        Name: TryInto<&'a PartialNameRef, Error = E>,
32        Error: From<E>,
33    {
34        let _name = partial.try_into()?;
35        match &self.state {
36            handle::State::Loose { store: _, .. } => {
37                todo!()
38            }
39        }
40    }
41}
42
43mod existing {
44    mod error {
45        use std::path::PathBuf;
46
47        /// The error returned by [file::Store::find_existing()][crate::file::Store::find_existing()].
48        #[derive(Debug, thiserror::Error)]
49        #[allow(missing_docs)]
50        pub enum Error {
51            #[error("An error occurred while finding a reference in the database")]
52            Find(#[from] crate::store::find::Error),
53            #[error("The ref partially named {name:?} could not be found")]
54            NotFound { name: PathBuf },
55        }
56    }
57
58    pub use error::Error;
59
60    use crate::{store, PartialNameRef, Reference};
61
62    impl store::Handle {
63        /// Similar to [`crate::file::Store::find()`] but a non-existing ref is treated as error.
64        pub fn find<'a, Name, E>(&self, _partial: Name) -> Result<Reference, Error>
65        where
66            Name: TryInto<&'a PartialNameRef, Error = E>,
67            crate::name::Error: From<E>,
68        {
69            todo!()
70            // match self.try_find(partial) {}
71            // match self.find_one_with_verified_input(path.to_partial_path().as_ref(), packed) {
72            //     Ok(Some(r)) => Ok(r),
73            //     Ok(None) => Err(Error::NotFound(path.to_partial_path().into_owned())),
74            //     Err(err) => Err(err.into()),
75            // }
76        }
77    }
78}