Skip to main content

Resources

Struct Resources 

Source
pub struct Resources { /* private fields */ }
Expand description

An application’s resources: values, files, and XML documents, each defined for one or more configurations.

IDs are assigned when compiling, by type and then by name, so adding a resource can change the IDs of others. Like aapt2, the compiler adds the minimum API level a configuration’s qualifiers imply (night is stored as night-v8).

use apk::res::{Config, Density, Resources, ResourceType};

let mut resources = Resources::new();
resources.string("app_name", "Postcard")?;
resources.localized_string("app_name", "fr".parse()?, "Carte postale")?;
let png = vec![0x89, b'P', b'N', b'G'];
resources.file(ResourceType::Mipmap, "ic_launcher", Config::for_density(Density::XHDPI), "png", png)?;

Implementations§

Source§

impl Resources

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, ty: ResourceType, name: &str) -> bool

Whether a resource with this type and name exists in any configuration.

Source

pub fn contains_variant( &self, ty: ResourceType, name: &str, config: Config, ) -> bool

Whether a resource with this type and name is defined for config.

Source

pub fn value( &mut self, ty: ResourceType, name: &str, config: Config, value: impl Into<Value>, ) -> Result<&mut Self, ResourceError>

Adds a simple value: a string, bool, integer, color, dimension, fraction, or a reference to another resource.

Source

pub fn string( &mut self, name: &str, value: impl Into<String>, ) -> Result<&mut Self, ResourceError>

Adds the default value of string resource name.

Source

pub fn localized_string( &mut self, name: &str, locale: Locale, value: impl Into<String>, ) -> Result<&mut Self, ResourceError>

Adds a translation of string resource name.

Source

pub fn file( &mut self, ty: ResourceType, name: &str, config: Config, extension: &str, content: impl Into<Content>, ) -> Result<&mut Self, ResourceError>

Adds a file stored as is, at res/<type>[-<qualifiers>]/<name>.<extension>. XML (except in raw files) must be added with xml, which compiles it.

Source

pub fn xml( &mut self, ty: ResourceType, name: &str, config: Config, document: Document, ) -> Result<&mut Self, ResourceError>

Adds an XML file resource, such as an adaptive icon, a color state list, or a network security config, compiled to binary XML. Its references may name other resources in this set.

Source

pub fn compile( &self, package: &PackageName, min_sdk: ApiLevel, ) -> Result<CompiledResources<'_>, ResourceError>

Assigns IDs and writes the resource table for package, for an app supporting min_sdk onwards.

Like aapt2, version qualifiers the minimum SDK already satisfies are dropped from the table (night-v8 becomes night); when that makes variants collide, the one with the highest version is kept.

Trait Implementations§

Source§

impl Clone for Resources

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 Debug for Resources

Source§

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

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

impl Default for Resources

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Resources

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Resources

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Same for T

Source§

type Output = T

Should always be Self
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.