pub struct ResourceIndex<'a> { /* private fields */ }Expand description
A parsed resources.index, borrowing the bytes it was read from.
use asc_hap::{ResourceIndex, ResourceRef, ResourceType};
let index = ResourceIndex::parse(bytes)?;
// `$r('app.string.app_name')` compiled to `{ id: 0x1000000, type: 10003, .. }`.
for resource in index.by_id(0x0100_0000) {
println!("{resource}"); // 0x01000000 string/app_name [base] "Bridge"
}
// `"label": "$string:app_name"` in module.json.
let label = ResourceRef::parse("$string:app_name").expect("a reference");
assert!(index.resolve(label).all(|r| r.kind() == ResourceType::String));Implementations§
Source§impl<'a> ResourceIndex<'a>
impl<'a> ResourceIndex<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<ResourceIndex<'a>, ResourceIndexError>
pub fn parse(bytes: &'a [u8]) -> Result<ResourceIndex<'a>, ResourceIndexError>
Reads the tables of an index. Values are not decoded here.
§Errors
ResourceIndexError::UnknownVersion when the header names
neither layout; the other variants when a table is cut short,
points outside the file or contradicts another.
pub fn format(&self) -> IndexFormat
Sourcepub fn qualifiers(&self) -> &[Qualifiers]
pub fn qualifiers(&self) -> &[Qualifiers]
The qualifier sets the index defines, in file order.
pub fn is_empty(&self) -> bool
Sourcepub fn iter(&self) -> Resources<'_> ⓘ
pub fn iter(&self) -> Resources<'_> ⓘ
Every value, by id and then by qualifier set in file order.
Sourcepub fn by_id(&self, id: u32) -> Resources<'_> ⓘ
pub fn by_id(&self, id: u32) -> Resources<'_> ⓘ
The values of the resource with this id, one per qualifier set.
The id is the id of a compiled $r(...) object and the
labelId / iconId / descriptionId of module.json.
Sourcepub fn by_name(&self, kind: ResourceType, name: &str) -> Resources<'_> ⓘ
pub fn by_name(&self, kind: ResourceType, name: &str) -> Resources<'_> ⓘ
The values of the resource with this type and name.
Sourcepub fn resolve(&self, reference: ResourceRef<'_>) -> Resources<'_> ⓘ
pub fn resolve(&self, reference: ResourceRef<'_>) -> Resources<'_> ⓘ
The values a reference points at: by name, or, for the decimal ids
that values inside the index use ($color:16777245), by id among
the resources of that type. A name wins over an id spelled alike.