dioxus-asset-resolver 0.7.2

Cross-platform asset resolver for manganis and dioxus
Documentation

The asset resolver for the Dioxus bundle format. Each platform has its own way of resolving assets. This crate handles resolving assets in a cross-platform way.

There are two broad locations for assets depending on the platform:

  • Web: Assets are stored on a remote server and fetched via HTTP requests.
  • Native: Assets are read from the local bundle. Each platform has its own bundle structure which may store assets as a file at a specific path or in an opaque format like Android's AssetManager.

[read_asset_bytes]( abstracts over both of these methods, allowing you to read the bytes of an asset regardless of the platform.

If you know you are on a desktop platform, you can use [asset_path] to resolve the path of an asset and read the contents with [std::fs].

Example

# async fn asset_example() {
use dioxus::prelude::*;

// Bundle the static JSON asset into the application
static JSON_ASSET: Asset = asset!("/assets/data.json");

// Read the bytes of the JSON asset
let bytes = dioxus::asset_resolver::read_asset_bytes(&JSON_ASSET).await.unwrap();

// Deserialize the JSON data
let json: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
assert_eq!(json["key"].as_str(), Some("value"));
# }