facto_core/registries/
trait_def.rs1use std::future::Future;
2use std::pin::Pin;
3
4use thiserror::Error;
5
6use crate::models::*;
7
8#[derive(Debug, Error)]
9pub enum RegistryError {
10 #[error("http error: {0}")]
11 Http(#[from] reqwest::Error),
12 #[error("timeout")]
13 Timeout,
14 #[error("not found")]
15 NotFound,
16 #[error("rate limited")]
17 RateLimited,
18 #[error("parse error: {0}")]
19 Parse(String),
20 #[error("not supported")]
21 NotSupported,
22}
23
24pub type RegistryResult<T> = Result<T, RegistryError>;
25
26pub trait Registry: Send + Sync {
31 fn id(&self) -> &str;
33 fn display_name(&self) -> &str;
35
36 fn get_package<'a>(
38 &'a self,
39 name: &'a str,
40 ) -> Pin<Box<dyn Future<Output = RegistryResult<PackageInfo>> + Send + 'a>>;
41 fn get_versions<'a>(
43 &'a self,
44 name: &'a str,
45 ) -> Pin<Box<dyn Future<Output = RegistryResult<Vec<VersionInfo>>> + Send + 'a>>;
46 fn search<'a>(
48 &'a self,
49 query: &'a str,
50 limit: usize,
51 ) -> Pin<Box<dyn Future<Output = RegistryResult<Vec<SearchResult>>> + Send + 'a>>;
52
53 fn supports_latest_version(&self) -> bool {
58 true
59 }
60}