elemental-driver 0.1.0

Driver library for Elemental, providing implementations for interacting with different modloaders and game versions.
Documentation
use anyhow::Result;
use async_trait::async_trait;
use elemental_core::{minecraft::MinecraftVersionId, storage::layout::Layout};
use elemental_schema::mojang::piston::PistonMetaData;

use crate::inspect::InstanceProbe;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DriverDescriptor {
    pub id: &'static str,
    pub name: &'static str,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InstalledDriver {
    pub driver: DriverDescriptor,
    pub driver_version: Option<String>,
    pub game_version: Option<MinecraftVersionId>,
    pub description: Option<String>,
}

impl InstalledDriver {
    pub fn version_json(
        descriptor: DriverDescriptor,
        metadata: &PistonMetaData,
        driver_version: Option<String>,
    ) -> Self {
        Self {
            driver: descriptor,
            driver_version,
            game_version: metadata
                .inherits_from
                .clone()
                .or_else(|| Some(metadata.id.clone()))
                .map(MinecraftVersionId::from),
            description: Some(metadata.release_type.clone()),
        }
    }
}

#[async_trait]
pub trait Driver<L: Layout, VL: Layout> {
    fn descriptor(&self) -> DriverDescriptor;

    async fn inspect(&self, probe: &InstanceProbe<L, VL>) -> Result<Option<InstalledDriver>>;
}