use std::collections::BTreeMap;
use martin_core::tiles::BoxedSource;
use crate::config::file::{ResolvedProcess, SourceBuildResult, TileSourceWarning};
use crate::reload::SourceProvenance;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Version {
Tracked(u128),
Opaque,
}
pub struct Discovered<A> {
pub sources: BTreeMap<String, (Version, A)>,
pub warnings: Vec<TileSourceWarning>,
}
impl<A> Discovered<A> {
#[must_use]
pub fn new(sources: BTreeMap<String, (Version, A)>) -> Self {
Self {
sources,
warnings: Vec::new(),
}
}
}
pub struct BuiltSource {
pub source: BoxedSource,
pub provenance: Option<SourceProvenance>,
pub process: Option<ResolvedProcess>,
}
impl From<BoxedSource> for BuiltSource {
fn from(source: BoxedSource) -> Self {
Self {
source,
provenance: None,
process: None,
}
}
}
pub trait Discovery: Send + Sync + 'static {
type Args: Clone + Send + Sync + 'static;
fn discover(&self) -> impl Future<Output = SourceBuildResult<Discovered<Self::Args>>> + Send;
fn build(
&self,
id: &str,
args: &Self::Args,
) -> impl Future<Output = SourceBuildResult<BuiltSource>> + Send;
fn process(&self) -> ResolvedProcess;
fn construction_warnings(&self) -> Vec<TileSourceWarning> {
Vec::new()
}
}