use crate::core::model::*;
use async_trait::async_trait;
use std::path::Path;
#[async_trait]
pub trait Ecosystem: Send + Sync {
fn name(&self) -> &'static str;
async fn detect(&self, path: &Path, content: Option<&str>) -> bool;
async fn read(&self, content: &str) -> miette::Result<Vec<Dependency>>;
async fn source(&self, coordinate: &Coordinate) -> miette::Result<Availability>;
fn scheme(&self) -> &dyn Scheme;
async fn write(
&self,
_content: &str,
_dependency: &Dependency,
_new_version: &Version,
) -> miette::Result<String> {
Err(miette::miette!(
"Ecosystem {} does not support writing",
self.name()
))
}
async fn write_batch(
&self,
content: &str,
edits: &[(&Dependency, &Version)],
) -> miette::Result<String> {
let mut result = content.to_string();
for (dep, version) in edits {
result = self.write(&result, dep, version).await?;
}
Ok(result)
}
}
pub trait Scheme: Send + Sync {
fn is_newer(&self, a: &Version, b: &Version) -> bool;
fn satisfies(&self, version: &Version, constraint: &Constraint) -> bool;
}