Skip to main content

ImageSource

Enum ImageSource 

Source
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

Source§

fn clone(&self) -> ImageSource

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

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

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

impl Default for ImageSource

Source§

fn default() -> Self

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

impl From<Arc<Vec<u8>>> for ImageSource

Source§

fn from(bytes: Arc<Vec<u8>>) -> Self

Converts to this type from the input type.
Source§

impl From<BitmapId> for ImageSource

Source§

fn from(id: BitmapId) -> Self

Converts to this type from the input type.
Source§

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§

fn from(name: ImageName) -> Self

Converts to this type from the input type.
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).

Source§

fn from(name: String) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for ImageSource

Source§

fn from(bytes: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<VectorName> for ImageSource

Source§

fn from(name: VectorName) -> Self

Converts to this type from the input type.
Source§

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.

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

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<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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Day API ↩ Guides· daybrite.dev