Trait rscache::definition::osrs::FetchDefinition
source · [−]pub trait FetchDefinition: Definition {
fn fetch_from_index<D>(
cache: &Cache,
index_id: u8
) -> Result<HashMap<u16, D>, Error>
where
D: Definition,
{ ... }
fn fetch_from_archive<D>(
cache: &Cache,
index_id: u8,
archive_id: u32
) -> Result<HashMap<u16, D>, Error>
where
D: Definition,
{ ... }
}
Expand description
Adds definition fetching from the cache to every struct that implements Definition
.
The main difference between fetch_from_index
and fetch_from_archive
:
fetch_from_index
will get only 1 definition from each archive making it a 1:1 relation.fetch_from_archive
will get multiple definitions from each archive making it a N:1 relation where N is atleast 1.
Provided methods
fn fetch_from_index<D>(
cache: &Cache,
index_id: u8
) -> Result<HashMap<u16, D>, Error> where
D: Definition,
fn fetch_from_index<D>(
cache: &Cache,
index_id: u8
) -> Result<HashMap<u16, D>, Error> where
D: Definition,
Fetches multiple definitions from every archive in the index.
Note: every archive contains only one definition. (1:1)
Errors
Can return multiple errors: if reading, decoding or parsing definition buffers fail.
fn fetch_from_archive<D>(
cache: &Cache,
index_id: u8,
archive_id: u32
) -> Result<HashMap<u16, D>, Error> where
D: Definition,
fn fetch_from_archive<D>(
cache: &Cache,
index_id: u8,
archive_id: u32
) -> Result<HashMap<u16, D>, Error> where
D: Definition,
Fetches multiple definitions from a single archive.
Note: every archive contains multiple definitions. (N:1)
Errors
Can return multiple errors: if reading, decoding or parsing definition buffers fail.
Examples
use rscache::definition::osrs::{
FetchDefinition,
ItemDefinition,
};
let index_id = 2; // Config index.
let archive_id = 10; // Archive containing item definitions.
let item_defs: HashMap<u16, ItemDefinition>
= ItemDefinition::fetch_from_archive(&cache, index_id, archive_id)?;