use std::convert::TryInto;
use crate::{store, PartialNameRef, Reference};
mod error {
use std::convert::Infallible;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("An error occurred while finding a reference in the loose file database")]
Loose(#[from] crate::file::find::Error),
#[error("The ref name or path is not a valid ref name")]
RefnameValidation(#[from] crate::name::Error),
}
impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!("this impl is needed to allow passing a known valid partial path as parameter")
}
}
}
pub use error::Error;
use crate::store::handle;
impl store::Handle {
pub fn try_find<'a, Name, E>(&self, partial: Name) -> Result<Option<Reference>, Error>
where
Name: TryInto<&'a PartialNameRef, Error = E>,
Error: From<E>,
{
let _name = partial.try_into()?;
match &self.state {
handle::State::Loose { store: _, .. } => {
todo!()
}
}
}
}
mod existing {
mod error {
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("An error occurred while finding a reference in the database")]
Find(#[from] crate::store::find::Error),
#[error("The ref partially named {name:?} could not be found")]
NotFound { name: PathBuf },
}
}
use std::convert::TryInto;
pub use error::Error;
use crate::{store, PartialNameRef, Reference};
impl store::Handle {
pub fn find<'a, Name, E>(&self, _partial: Name) -> Result<Reference, Error>
where
Name: TryInto<&'a PartialNameRef, Error = E>,
crate::name::Error: From<E>,
{
todo!()
}
}
}