lighty_loaders/utils/
query.rs1use crate::types::version_metadata::Version;
2use crate::types::VersionInfo;
3use lighty_core::QueryError;
4use async_trait::async_trait;
5use std::hash::Hash;
6
7pub type Result<T> = std::result::Result<T, QueryError>;
8
9#[async_trait]
15pub trait Query: Send + Sync {
16 type Query: Eq + Hash + Clone + Send + Sync + 'static;
17
18 type Data: Clone + Send + Sync + 'static;
19
20 type Raw: Send + Sync + 'static;
21
22
23 fn name() -> &'static str;
25
26 async fn fetch_full_data<V: VersionInfo>(version: &V) -> Result<Self::Raw>;
28
29 async fn extract<V: VersionInfo>(version: &V, query: &Self::Query, raw: &Self::Raw) -> Result<Self::Data>;
31
32 async fn version_builder<V: VersionInfo>(version: &V, full_data: &Self::Raw) -> Result<Version>;
34}
35
36
37#[derive(Debug, Clone, PartialEq, Eq, Hash)]
38pub struct InstanceKey {
39 pub name: String,
40 pub minecraft_version: String,
41 pub loader_version: String,
42}
43
44impl InstanceKey {
45 pub fn of<V: VersionInfo>(version: &V) -> Self {
46 Self {
47 name: version.name().to_string(),
48 minecraft_version: version.minecraft_version().to_string(),
49 loader_version: version.loader_version().to_string(),
50 }
51 }
52}
53
54#[derive(Debug, Clone, PartialEq, Eq, Hash)]
56pub struct QueryKey<Q> {
57 pub instance: InstanceKey,
58 pub query: Q,
59}
60