pub enum ImageSource<'a> {
    Uri(Cow<'a, str>),
    Texture(SizedTexture),
    Bytes {
        uri: Cow<'static, str>,
        bytes: Bytes,
    },
}
Expand description

This type tells the Ui how to load an image.

This is used by Image::new and Ui::image.

Variants§

§

Uri(Cow<'a, str>)

Load the image from a URI, e.g. https://example.com/image.png.

This could be a file:// path, https:// url, bytes:// identifier, or some other scheme.

How the URI will be turned into a texture for rendering purposes is up to the registered loaders to handle.

See crate::load for more information.

§

Texture(SizedTexture)

Load the image from an existing texture.

The user is responsible for loading the texture, determining its size, and allocating a TextureId for it.

§

Bytes

Fields

§uri: Cow<'static, str>

The unique identifier for this image, e.g. bytes://my_logo.png.

You should use a proper extension (.jpg, .png, .svg, etc) for the image to load properly.

Use the bytes:// scheme for the URI for better error messages.

§bytes: Bytes

Load the image from some raw bytes.

The Bytes may be:

  • 'static, obtained from include_bytes! or similar
  • Anything that can be converted to Arc<[u8]>

This instructs the Ui to cache the raw bytes, which are then further processed by any registered loaders.

See also include_image for an easy way to load and display static images.

See crate::load for more information.

Implementations§

source§

impl<'a> ImageSource<'a>

source

pub fn texture_size(&self) -> Option<Vec2>

Size of the texture, if known.

source

pub fn load( self, ctx: &Context, texture_options: TextureOptions, size_hint: SizeHint ) -> TextureLoadResult

Errors

Failure to load the texture.

source

pub fn uri(&self) -> Option<&str>

Get the uri that this image was constructed from.

This will return None for Self::Texture.

Trait Implementations§

source§

impl<'a> Clone for ImageSource<'a>

source§

fn clone(&self) -> ImageSource<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for ImageSource<'a>

source§

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

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

impl<'a> From<&'a Cow<'a, str>> for ImageSource<'a>

source§

fn from(value: &'a Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a String> for ImageSource<'a>

source§

fn from(value: &'a String) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for ImageSource<'a>

source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Bytes>> From<(&'static str, T)> for ImageSource<'static>

source§

fn from((uri, bytes): (&'static str, T)) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Bytes>> From<(Cow<'static, str>, T)> for ImageSource<'static>

source§

fn from((uri, bytes): (Cow<'static, str>, T)) -> Self

Converts to this type from the input type.
source§

impl<T: Into<Bytes>> From<(String, T)> for ImageSource<'static>

source§

fn from((uri, bytes): (String, T)) -> Self

Converts to this type from the input type.
source§

impl<'a> From<Cow<'a, str>> for ImageSource<'a>

source§

fn from(value: Cow<'a, str>) -> Self

Converts to this type from the input type.
source§

impl From<String> for ImageSource<'static>

source§

fn from(value: String) -> Self

Converts to this type from the input type.
source§

impl<T: Into<SizedTexture>> From<T> for ImageSource<'static>

source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ImageSource<'a>

§

impl<'a> Send for ImageSource<'a>

§

impl<'a> Sync for ImageSource<'a>

§

impl<'a> Unpin for ImageSource<'a>

§

impl<'a> UnwindSafe for ImageSource<'a>

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

§

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

§

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

§

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

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,