pub trait Registry: Send + Sync {
// Required methods
fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn package_url(&self, name: &str) -> String;
fn as_any(&self) -> &dyn Any;
}Expand description
Generic package registry interface.
Implementors provide access to a package registry (crates.io, npm, PyPI, etc.) with version lookup, search, and metadata retrieval capabilities.
All methods return Result<T> to allow graceful error handling.
LSP handlers must never panic on registry errors.
§Type Erasure
This trait uses Box<dyn Trait> return types instead of associated types
to allow runtime polymorphism and dynamic ecosystem registration.
§Examples
use deps_core::{Registry, Version, Metadata};
use async_trait::async_trait;
use std::any::Any;
struct MyRegistry;
#[derive(Clone)]
struct MyVersion {
version: String,
}
impl Version for MyVersion {
fn version_string(&self) -> &str {
&self.version
}
fn is_yanked(&self) -> bool {
false
}
fn as_any(&self) -> &dyn Any {
self
}
}
#[derive(Clone)]
struct MyMetadata {
name: String,
}
impl Metadata for MyMetadata {
fn name(&self) -> &str {
&self.name
}
fn description(&self) -> Option<&str> {
None
}
fn repository(&self) -> Option<&str> {
None
}
fn documentation(&self) -> Option<&str> {
None
}
fn latest_version(&self) -> &str {
"1.0.0"
}
fn as_any(&self) -> &dyn Any {
self
}
}
#[async_trait]
impl Registry for MyRegistry {
async fn get_versions(&self, name: &str) -> deps_core::error::Result<Vec<Box<dyn Version>>> {
Ok(vec![Box::new(MyVersion { version: "1.0.0".into() })])
}
async fn get_latest_matching(
&self,
_name: &str,
_req: &str,
) -> deps_core::error::Result<Option<Box<dyn Version>>> {
Ok(None)
}
async fn search(&self, _query: &str, _limit: usize) -> deps_core::error::Result<Vec<Box<dyn Metadata>>> {
Ok(vec![])
}
fn package_url(&self, name: &str) -> String {
format!("https://example.com/packages/{}", name)
}
fn as_any(&self) -> &dyn Any {
self
}
}Required Methods§
Sourcefn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_versions<'life0, 'life1, 'async_trait>(
&'life0 self,
name: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Version>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Fetches all available versions for a package.
Returns versions sorted newest-first. May include yanked/deprecated versions.
§Errors
Returns error if:
- Package does not exist
- Network request fails
- Response parsing fails
Sourcefn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_latest_matching<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
name: &'life1 str,
req: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Box<dyn Version>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Finds the latest version matching a version requirement.
Only returns stable (non-yanked, non-deprecated) versions unless explicitly requested in the version requirement.
§Arguments
name- Package namereq- Version requirement string (e.g., “^1.0”, “>=2.0”)
§Returns
Ok(Some(version))- Latest matching version foundOk(None)- No matching version foundErr(_)- Network or parsing error
Sourcefn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn search<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Metadata>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Searches for packages by name or keywords.
Returns up to limit results sorted by relevance/popularity.
§Errors
Returns error if network request or parsing fails.
Sourcefn package_url(&self, name: &str) -> String
fn package_url(&self, name: &str) -> String
Package URL for ecosystem (e.g., https://crates.io/crates/serde)
Returns a URL that links to the package page on the registry website.