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