Skip to main content

ImageSource

Struct ImageSource 

Source
pub struct ImageSource {
    pub uri: Arc<str>,
    pub size: Option<Size<Points>>,
    pub scales: ImageScales,
    pub data: Option<ImageData>,
}
Expand description

An image source.

Fields§

§uri: Arc<str>

https://…, asset:/path (bundled file), a file path, a data: URI or a blob: URL (URL.createObjectURL). A source with Self::data goes by a short key instead of a data: URI (crate::image).

§size: Option<Size<Points>>

Natural size in points, when known up front (bundled assets): used as the intrinsic layout size.

§scales: ImageScales

The pixel densities a bundled asset ships in (a.png, a@2x.png, …): the core mounts the one for the screen’s pixel ratio. Empty for a single file.

§data: Option<ImageData>

The image’s bytes when they are in memory (a data: URI’s, the blob of a blob: URL): the platforms decode these instead of loading Self::uri, which stays the cache key.

Implementations§

Source§

impl ImageSource

Source

pub fn inline(self) -> ImageSource

This source with its bytes in hand when its URI holds them: a data: URI decoded (once, when the source is set) and named by a short key. Other sources stay as they are. A data: URI that does not decode becomes an empty one (the platforms then report the error): left as it is, an app could write another image’s key (data:<type>;nsh-key=<digest>, which has no comma) and ask the process-wide caches whether some surface shows those bytes.

Source

pub fn natural_size(&self) -> Option<Size<Points>>

Its natural size in points: Self::size, else, for bytes in hand (a data: URI, a blob), the size their header gives, one pixel a point. A URL’s size is known only once it loads.

Source

pub fn with_bytes(self, mime: &str, data: ImageData) -> ImageSource

This source showing data, of media type mime (a blob’s bytes), named by a digest of the bytes: equal images share their loads and cache entries, whatever URL named them.

Source

pub fn at_pixel_ratio(&self, pixel_ratio: f32) -> ImageSource

This source for a screen of pixel_ratio device pixels per point: the Self::uri_for the core picks for what it mounts, for what goes around it (a menu item’s icon).

Trait Implementations§

Source§

impl Clone for ImageSource

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 ImageSource

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 HostValue for ImageSource

"https://…" or a bundled asset { url, size: { width, height }, scales }.

Source§

fn decode<I: HostInput>(input: &I, _: &mut HostCx) -> Option<Self>

The value in input.
Source§

fn ts_type(_: &mut TsTypes) -> String

Its TypeScript type, declaring the named types it uses.
Source§

impl PartialEq for ImageSource

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 ImageSource

Auto Trait Implementations§

§

impl !RefUnwindSafe for ImageSource

§

impl !UnwindSafe for ImageSource

§

impl Forget for ImageSource

§

impl Freeze for ImageSource
where *const ArcInner<str> is !null: Freeze, PhantomData<ArcInner<str>>: Freeze, *const ArcInner<dyn AsRef<[u8]> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn AsRef<[u8]> + Sync + Send>>: Freeze, *const ArcInner<Rgba> is !null: Freeze, PhantomData<ArcInner<Rgba>>: Freeze,

§

impl Move for ImageSource

§

impl Send for ImageSource
where Arc<str>: Send, Arc<dyn AsRef<[u8]> + Sync + Send>: Send, Arc<Rgba>: Send,

§

impl Sync for ImageSource
where Arc<str>: Sync, Arc<dyn AsRef<[u8]> + Sync + Send>: Sync, Arc<Rgba>: Sync,

§

impl Unpin for ImageSource
where Arc<str>: Unpin, Arc<dyn AsRef<[u8]> + Sync + Send>: Unpin, Arc<Rgba>: Unpin,

§

impl UnsafeUnpin for ImageSource
where *const ArcInner<str> is !null: UnsafeUnpin, PhantomData<ArcInner<str>>: UnsafeUnpin, *const ArcInner<dyn AsRef<[u8]> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn AsRef<[u8]> + Sync + Send>>: UnsafeUnpin, *const ArcInner<Rgba> is !null: UnsafeUnpin, PhantomData<ArcInner<Rgba>>: UnsafeUnpin,

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