Skip to main content

decode_image_async

Function decode_image_async 

Source
pub async fn decode_image_async(
    bytes: Vec<u8>,
) -> Result<ImageSource, ImageDecodeError>
Expand description

Off-thread image decode: decode_image_async wraps the existing synchronous ImageSource::decode in spawn_blocking, so it composes with use_task for the full load/error/ready idiom without ever blocking the UI thread on a decode. See image_async’s module docs for why this lives in the facade rather than frust-widgets (which stays reactive-free by charter) and for the Arc-move contract the decoded ImageSource crosses threads under. Off-thread image decode: decode_image_async wraps the existing synchronous ImageSource::decode in spawn_blocking, so it composes with use_task for the full load/error/ready idiom without ever blocking the UI thread on a decode. See image_async’s module docs for why this lives in the facade rather than frust-widgets (which stays reactive-free by charter) and for the Arc-move contract the decoded ImageSource crosses threads under. Off-thread image decode: decode_image_async wraps the existing synchronous ImageSource::decode in spawn_blocking, so it composes with use_task for the full load/error/ready idiom without ever blocking the UI thread on a decode. See image_async’s module docs for why this lives in the facade rather than frust-widgets (which stays reactive-free by charter) and for the Arc-move contract the decoded ImageSource crosses threads under. Decodes PNG/JPEG bytes off the UI thread via frust_reactive::spawn_blocking, returning the same ImageSource ImageSource::decode would build synchronously.

bytes moves into the background closure (no copy beyond the initial Vec transfer); the decoded ImageSource moves back — see this module’s docs for the Arc-move contract.

Compose with use_task for the full load/error/ready idiom:

ⓘ
let image = use_task(|| async { frust::decode_image_async(bytes.clone()).await });