Query System
Query Trait Definition
use async_trait::async_trait;
use std::hash::Hash;
use std::time::Duration;
#[async_trait]
pub trait Query: Send + Sync {
/// Type of query (enum defining what to fetch)
type Query: Eq + Hash + Clone + Send + Sync + 'static;
/// Type of extracted data (usually VersionMetaData)
type Data: Clone + Send + Sync + 'static;
/// Type of raw data from API (JSON or typed struct)
type Raw: Send + Sync + 'static;
/// Loader name (e.g., "vanilla", "fabric")
fn name() -> &'static str;
/// Fetch raw manifest from external source
async fn fetch_full_data<V: VersionInfo>(version: &V) -> Result<Self::Raw>;
/// Extract specific data from raw manifest
async fn extract<V: VersionInfo>(
version: &V,
query: &Self::Query,
raw: &Self::Raw
) -> Result<Self::Data>;
/// Global TTL for cache (default: 1 hour)
fn cache_ttl() -> Duration {
Duration::from_secs(3600)
}
/// Per-query TTL (optional override)
fn cache_ttl_for_query(_query: &Self::Query) -> Duration {
Self::cache_ttl()
}
/// Build complete Version metadata
async fn version_builder<V: VersionInfo>(
version: &V,
full_data: &Self::Raw
) -> Result<Version>;
}Implementing a Custom Query
Example: Custom Mod Loader
Step 1: Define Module Structure
Step 2: Define Metadata Types
Step 3: Implement Query
Step 4: Add to Loader Enum
Step 5: Implement LoaderExtensions Dispatch
Step 6: Add Feature Flag
Step 7: Module Exports
Usage
Merging with Vanilla
Data Flow Diagrams
VersionInfo Data Flow
LoaderExtensions Data Flow
Implementing Custom VersionInfo
Event Integration
Testing Your Query
Related Documentation
Last updated