[][src]Trait rusty_boy_advance::utils::AsBoolSlice

pub trait AsBoolSlice {
    fn is_set(self, mask: u8) -> bool;
fn is_set_n(self, n: u8) -> bool;
fn as_bools(self) -> [bool; 8]; }

Utility impl on u8's for some kind of "bit pattern matching".

Consider performance implications (If any) later.

Examples

use rusty_boy_advance::utils::AsBoolSlice;
fn disassemble(x: u8) -> Option<&'static str> {
  const T: bool = true;
  const F: bool = false;
  match x.as_bools() {
    [T, T, T, _, _, _, _, _] => Some("First three bits set"),
    [_, _, F, _, _, _, _, _] => Some("Third bit not set"),
    _ => None,
  }
}
assert!(disassemble(0b1110_0000u8) == Some("First three bits set"));
assert!(disassemble(0b1110_1100u8) == Some("First three bits set"));
assert!(disassemble(0b1100_1100u8) == Some("Third bit not set"));
assert!(disassemble(0b0000_1100u8) == Some("Third bit not set"));
assert!(disassemble(0b0010_1100u8) == None);

Required methods

fn is_set(self, mask: u8) -> bool

fn is_set_n(self, n: u8) -> bool

fn as_bools(self) -> [bool; 8]

Loading content...

Implementations on Foreign Types

impl AsBoolSlice for u8[src]

Loading content...

Implementors

Loading content...