Skip to main content

ResourceIndex

Struct ResourceIndex 

Source
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>

Source

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.

Source

pub fn version(&self) -> &str

The version text of the header: Restool 5.0.1.011.

Source

pub fn format(&self) -> IndexFormat

Which of the two layouts the file uses.

Source

pub fn qualifiers(&self) -> &[Qualifiers]

The qualifier sets the index defines, in file order.

Source

pub fn len(&self) -> usize

Number of values: one per resource and qualifier set.

Source

pub fn is_empty(&self) -> bool

Whether the index holds no values at all.

Source

pub fn iter(&self) -> Resources<'_> ⓘ

Every value, by id and then by qualifier set in file order.

Source

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.

Source

pub fn by_name(&self, kind: ResourceType, name: &str) -> Resources<'_> ⓘ

The values of the resource with this type and name.

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for ResourceIndex<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ResourceIndex<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'r> IntoIterator for &'r ResourceIndex<'_>

Source§

type Item = Resource<'r>

The type of the elements being iterated over.
Source§

type IntoIter = Resources<'r>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Resources<'r> ⓘ

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'a> Forget for ResourceIndex<'a>

§

impl<'a> Freeze for ResourceIndex<'a>

§

impl<'a> Move for ResourceIndex<'a>

§

impl<'a> RefUnwindSafe for ResourceIndex<'a>

§

impl<'a> Send for ResourceIndex<'a>

§

impl<'a> Sync for ResourceIndex<'a>

§

impl<'a> Unpin for ResourceIndex<'a>

§

impl<'a> UnsafeUnpin for ResourceIndex<'a>

§

impl<'a> UnwindSafe for ResourceIndex<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.