pub struct IconData { /* private fields */ }Expand description
A decoded window/app icon: tightly-packed, non-premultiplied RGBA8 rows,
top-to-bottom — the one representation every desktop platform can be fed
from (winit’s Icon::from_rgba, an NSImage bitmap rep, an HICON DIB).
Decoding a PNG/ICNS/ICO into this is the caller’s job: this crate carries no image decoder, and the tooling tier already owns the icon pipeline.
The rgba/width/height triple is an invariant, not three independent
fields (rgba.len() == width * height * 4), so the fields are private and
IconData::from_rgba is the only way in — an inconsistent icon reaches a
platform API as a buffer overrun, not a wrong picture.
Debug is hand-written rather than derived (see the manual impl below):
a derived one would dump the whole pixel buffer, drowning a log line in
thousands of byte values for even a small icon.
Implementations§
Source§impl IconData
impl IconData
Sourcepub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Option<Self>
pub fn from_rgba(rgba: Vec<u8>, width: u32, height: u32) -> Option<Self>
Wrap decoded RGBA8 pixels, or None when they do not describe a
width × height image: either dimension is zero or exceeds
MAX_ICON_SIDE, or rgba.len() != width * height * 4.
Option rather than a <Type>Error enum because there is exactly one
failure mode and nothing to match on — and this crate carries no
thiserror dependency to add one with (version pins are law). The
caller that decoded the image is the one holding the context worth
reporting.
Check order matters. The dimension cap runs before the size
arithmetic below it, so a hostile width/height is rejected on a
cheap comparison rather than reaching the multiply (or, on a caller
that already allocated rgba to match, whatever cost that
allocation carried) at all.
Trait Implementations§
impl Eq for IconData
impl StructuralPartialEq for IconData
Auto Trait Implementations§
impl Freeze for IconData
impl RefUnwindSafe for IconData
impl Send for IconData
impl Sync for IconData
impl Unpin for IconData
impl UnsafeUnpin for IconData
impl UnwindSafe for IconData
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.