pub enum ImageSource {
Named(String),
Bytes(Arc<Vec<u8>>),
Decoded(BitmapId),
}Expand description
Where a raster image’s pixels come from (docs/images.md).
One currency for both halves of the same question: Named is the staged asset every
image(res::images::…) has always drawn, Bytes is an encoded PNG/JPEG the app already
holds (a download, a file the user picked, a clipboard paste), and Decoded names an image
the toolkit decoded once so several nodes (and the canvas) share it.
Variants§
Named(String)
A staged asset name, resolved through the backend’s own pipeline (§18.2).
Bytes(Arc<Vec<u8>>)
Encoded bytes (PNG/JPEG/…) the app owns, decoded by the platform’s own decoder. Shared rather than copied: handing over a new buffer is a refcount bump.
Decoded(BitmapId)
An image already decoded through Toolkit::decode_image.
Trait Implementations§
Source§impl Clone for ImageSource
impl Clone for ImageSource
Source§fn clone(&self) -> ImageSource
fn clone(&self) -> ImageSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageSource
Logs the buffer’s length, never its contents: a Debug that dumped a megabyte of pixels
into a trace line would make the trace useless and slow.
impl Debug for ImageSource
Logs the buffer’s length, never its contents: a Debug that dumped a megabyte of pixels
into a trace line would make the trace useless and slow.
Source§impl Default for ImageSource
impl Default for ImageSource
Source§impl From<BitmapId> for ImageSource
impl From<BitmapId> for ImageSource
Source§impl From<ImageName> for ImageSource
A staged asset name is a source, so image(res::images::cover) keeps compiling unchanged.
impl From<ImageName> for ImageSource
A staged asset name is a source, so image(res::images::cover) keeps compiling unchanged.
There is no From<&str> here, for the same reason resource::ImageName has none:
image("typo") must stay a compile error rather than a blank view at runtime (resource.rs).
A path or URL string is not a source either: read the bytes and hand those over.
Source§impl From<String> for ImageSource
An owned string is a name, not bytes: the same conversion resource::ImageName offers for
a name computed at runtime, and the reason image(some_string) keeps compiling. A &str
still converts nowhere, so image("typo") stays a compile error (resource.rs).
impl From<String> for ImageSource
An owned string is a name, not bytes: the same conversion resource::ImageName offers for
a name computed at runtime, and the reason image(some_string) keeps compiling. A &str
still converts nowhere, so image("typo") stays a compile error (resource.rs).
Source§impl From<VectorName> for ImageSource
impl From<VectorName> for ImageSource
Source§fn from(name: VectorName) -> Self
fn from(name: VectorName) -> Self
Source§impl PartialEq for ImageSource
Bytes compare by identity, not content.
impl PartialEq for ImageSource
Bytes compare by identity, not content.
This is the equality a binding gates on (§4.2), so it runs on every evaluation, and
comparing two multi-megabyte buffers byte by byte would cost far more than the redundant
decode it saves. Handing over a distinct buffer holding the same pixels therefore re-decodes,
which is the same trade Arc::ptr_eq makes wherever else Day carries shared buffers.