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 crate::TextureId
for it.
Bytes
Load the image from some raw bytes.
The Bytes
may be:
'static
, obtained frominclude_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 crate::include_image
for an easy way to load and display static images.
See crate::load
for more information.
Implementations§
§impl<'a> ImageSource<'a>
impl<'a> ImageSource<'a>
pub fn texture_size(&self) -> Option<Vec2>
pub fn texture_size(&self) -> Option<Vec2>
Size of the texture, if known.
pub fn load(
self,
ctx: &Context,
texture_options: TextureOptions,
size_hint: SizeHint
) -> Result<TexturePoll, LoadError>
pub fn load( self, ctx: &Context, texture_options: TextureOptions, size_hint: SizeHint ) -> Result<TexturePoll, LoadError>
§Errors
Failure to load the texture.
pub fn uri(&self) -> Option<&str>
pub fn uri(&self) -> Option<&str>
Get the uri
that this image was constructed from.
This will return None
for Self::Texture
.
Trait Implementations§
§impl<'a> Clone for ImageSource<'a>
impl<'a> Clone for ImageSource<'a>
§fn clone(&self) -> ImageSource<'a>
fn clone(&self) -> ImageSource<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<'a> Debug for ImageSource<'a>
impl<'a> Debug for ImageSource<'a>
§impl<'a> From<&'a Cow<'a, str>> for ImageSource<'a>
impl<'a> From<&'a Cow<'a, str>> for ImageSource<'a>
§fn from(value: &'a Cow<'a, str>) -> ImageSource<'a>
fn from(value: &'a Cow<'a, str>) -> ImageSource<'a>
§impl<'a> From<&'a String> for ImageSource<'a>
impl<'a> From<&'a String> for ImageSource<'a>
§fn from(value: &'a String) -> ImageSource<'a>
fn from(value: &'a String) -> ImageSource<'a>
§impl<'a> From<&'a str> for ImageSource<'a>
impl<'a> From<&'a str> for ImageSource<'a>
§fn from(value: &'a str) -> ImageSource<'a>
fn from(value: &'a str) -> ImageSource<'a>
§impl<T> From<(&'static str, T)> for ImageSource<'static>
impl<T> From<(&'static str, T)> for ImageSource<'static>
§fn from(_: (&'static str, T)) -> ImageSource<'static>
fn from(_: (&'static str, T)) -> ImageSource<'static>
§impl<T> From<(Cow<'static, str>, T)> for ImageSource<'static>
impl<T> From<(Cow<'static, str>, T)> for ImageSource<'static>
§fn from(_: (Cow<'static, str>, T)) -> ImageSource<'static>
fn from(_: (Cow<'static, str>, T)) -> ImageSource<'static>
§impl<T> From<(String, T)> for ImageSource<'static>
impl<T> From<(String, T)> for ImageSource<'static>
§fn from(_: (String, T)) -> ImageSource<'static>
fn from(_: (String, T)) -> ImageSource<'static>
§impl<'a> From<Cow<'a, str>> for ImageSource<'a>
impl<'a> From<Cow<'a, str>> for ImageSource<'a>
§fn from(value: Cow<'a, str>) -> ImageSource<'a>
fn from(value: Cow<'a, str>) -> ImageSource<'a>
§impl From<String> for ImageSource<'static>
impl From<String> for ImageSource<'static>
§fn from(value: String) -> ImageSource<'static>
fn from(value: String) -> ImageSource<'static>
§impl<T> From<T> for ImageSource<'static>where
T: Into<SizedTexture>,
impl<T> From<T> for ImageSource<'static>where
T: Into<SizedTexture>,
§fn from(value: T) -> ImageSource<'static>
fn from(value: T) -> ImageSource<'static>
Auto Trait Implementations§
impl<'a> Freeze for ImageSource<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request