tame_index/index/
combo.rs#[cfg(feature = "local")]
use crate::index::LocalRegistry;
use crate::{
index::{FileLock, RemoteGitIndex, RemoteSparseIndex},
Error, IndexKrate, KrateName,
};
#[non_exhaustive]
pub enum ComboIndex {
Git(RemoteGitIndex),
Sparse(RemoteSparseIndex),
#[cfg(feature = "local")]
Local(LocalRegistry),
}
impl ComboIndex {
#[inline]
pub fn krate(
&self,
name: KrateName<'_>,
write_cache_entry: bool,
lock: &FileLock,
) -> Result<Option<IndexKrate>, Error> {
match self {
Self::Git(index) => index.krate(name, write_cache_entry, lock),
Self::Sparse(index) => index.krate(name, write_cache_entry, lock),
#[cfg(feature = "local")]
Self::Local(lr) => lr.cached_krate(name, lock),
}
}
#[inline]
pub fn cached_krate(
&self,
name: KrateName<'_>,
lock: &FileLock,
) -> Result<Option<IndexKrate>, Error> {
match self {
Self::Git(index) => index.cached_krate(name, lock),
Self::Sparse(index) => index.cached_krate(name, lock),
#[cfg(feature = "local")]
Self::Local(lr) => lr.cached_krate(name, lock),
}
}
}
impl From<RemoteGitIndex> for ComboIndex {
#[inline]
fn from(index: RemoteGitIndex) -> Self {
Self::Git(index)
}
}
impl From<RemoteSparseIndex> for ComboIndex {
#[inline]
fn from(index: RemoteSparseIndex) -> Self {
Self::Sparse(index)
}
}
#[cfg(feature = "local")]
impl From<LocalRegistry> for ComboIndex {
#[inline]
fn from(local: LocalRegistry) -> Self {
Self::Local(local)
}
}