[−][src]Trait ikon::decode::Decode
The Decode
trait represents a generic icon family decoder, providing
methods for generating icons from byte streams, as well as functionality
querying and inspecting icon families.
Example
In this example we'll create a very simple Decode
implementor whose
icons are positive integers. First of all, we'll need a Icon
type:
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct Icon(pub u16); impl Icon for ikon::Icon { fn size(&self) -> u32 { if self.0 == 0 { 256 } else { *self.0 } } }
Note that Icon(0)
represents Icon(256)
. We can then implement our
IconFamily
type.
#[derive(Clone)] pub struct IconFamily { internal: HashMap<Icon, DynamicImage> } impl Decode for IconFamily { type Icon = Icon; fn read<R: Read>(r: R) -> io::Result<Self> { // Some decoding in here . . . } fn len(&self) -> usize { self.internal.len() } fn contains_icon(icon: &Self::Icon) -> bool { self.internal.contains_entry(icon) } fn get(&self, icon: &Self::Icon) -> Option<&Image> { self.internal.get(icon) } fn icons(&self) -> Iter<(Self::Icon, Image)> { let output = Vec::with_capacity(self.len()); for icon in self.internal { output.push(icon); } output.iter() } }
Associated Types
Loading content...Required methods
fn read<R: Read + Seek>(r: R) -> Result<Self, DecodingError>
Parses and loads an icon into memmory.
fn len(&self) -> usize
fn contains_icon(&self, icon: &Self::Icon) -> bool
Returns true
if the icon includes an icon associated with icon
.
Otherwise returns false
.
Example
if icon.contains_icon(&Icon(32)) { // Do this . . . } else { // Do that . . . }
fn get(&self, icon: &Self::Icon) -> Option<&Image>
Returns Some(icon)
if the icon includes an icon associated with icon
.
Otherwise returns None
.
Example
if let Some(icon) = icon.icon(&Icon(32)) { // Process the icon . . . }
fn icons(&'a self) -> Self::Icons
Returns an iterator over the icons of the icon.
Example
for (icon, image) in icon.icons() { // Do something . . . }