summaryrefslogtreecommitdiff
path: root/shared/src/loader.rs
blob: 0172265b816cb637d083115085cfc15e88a62c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
use crate::{helper::ReadWrite, packets::Resource};
use anyhow::Result;
use std::io::Cursor;

pub trait ResLoader: Send + Sync {
    fn get_raw(&self, res: Resource) -> impl Future<Output = Result<Vec<u8>>> + Send;
    fn get<R: ReadWrite + Sync>(
        &self,
        res: &Resource<R>,
    ) -> impl Future<Output = Result<R>> + Send {
        async { R::read(&mut Cursor::new(self.get_raw(res.to_generic()).await?)) }
    }
}