pub trait Bitline {
Show 25 methods // Required methods fn as_empty() -> Self; fn as_full() -> Self; fn by_range(begin: usize, end: usize) -> Self; fn is_empty(&self) -> bool; fn is_not_empty(&self) -> bool; fn is_full(&self) -> bool; fn is_not_full(&self) -> bool; fn first_index(&self) -> Option<usize>; fn last_index(&self) -> Option<usize>; fn radius(&self, n: usize) -> Self; fn around(&self, n: usize) -> Self; fn with_around(&self, n: usize) -> Self; fn first_bit(&self) -> Self; fn last_bit(&self) -> Self; fn first_bits(&self) -> Self; fn last_bits(&self) -> Self; fn filled_first_bit_to_last_bit(&self) -> Self; fn bytes_length() -> usize; fn length() -> usize; fn num_bits(&self) -> usize; fn includes(&self, other: Self) -> bool; fn overlaps(&self, other: Self) -> bool; fn range(&self, begin: usize, end: usize) -> Self; fn remove(&self, other: Self) -> Self; fn bit_repr(&self) -> String;
}

Required Methods§

source

fn as_empty() -> Self

Return the bits all set to 0

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!(Bitline8::as_empty(), 0b00000000);
source

fn as_full() -> Self

Return the bits all set to 1

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!(Bitline8::as_full(), 0b11111111);
source

fn by_range(begin: usize, end: usize) -> Self

Return the bits standing in the given range.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!(Bitline8::by_range(2, 5), 0b00111000_u8);
source

fn is_empty(&self) -> bool

Return true if the bit is filled with zero.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert!(!0b00111000_u8.is_empty());
assert!(0b00000000_u8.is_empty());
source

fn is_not_empty(&self) -> bool

Return true if the bit is not filled with zero.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert!(0b00111000_u8.is_not_empty());
assert!(!0b00000000_u8.is_not_empty());
source

fn is_full(&self) -> bool

Return true if the bit is filled with one.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert!((0b11111111 as Bitline8).is_full());
assert!(!(0b01111111 as Bitline8).is_full());
source

fn is_not_full(&self) -> bool

Return true if the bit is not filled with one.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert!((0b01111111 as Bitline8).is_not_full());
assert!(!(0b11111111 as Bitline8).is_not_full());
source

fn first_index(&self) -> Option<usize>

Return the first bit index that is set to one. If there is no bit set to one, return None.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!((0b00111000 as Bitline8).first_index(), Some(2));
assert_eq!((0b00000000 as Bitline8).first_index(), None);
source

fn last_index(&self) -> Option<usize>

Return the last bit index that is set to one. If there is no bit set to one, return None.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!((0b00111000 as Bitline8).last_index(), Some(4));
assert_eq!((0b00000000 as Bitline8).last_index(), None);
source

fn radius(&self, n: usize) -> Self

Return the bits standing in n distance from the original starting bit. If there is no bit set to one, return None.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b00001000 as Bitline8;
assert_eq!(bitline.radius(0), 0b00000000);
assert_eq!(bitline.radius(1), 0b00010100);
assert_eq!(bitline.radius(2), 0b00100010);

let bitline = 0b00000000 as Bitline8;
assert_eq!(bitline.radius(0), 0b00000000);
assert_eq!(bitline.radius(1), 0b00000000);
assert_eq!(bitline.radius(2), 0b00000000);

let bitline = 0b00100100 as Bitline8;
assert_eq!(bitline.radius(0), 0b00000000);
assert_eq!(bitline.radius(1), 0b01011010);
assert_eq!(bitline.radius(2), 0b10011001);
source

fn around(&self, n: usize) -> Self

Return all bits standing between n distance from the standing bits (without original standing bits).

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b00001000 as Bitline8;
assert_eq!(bitline.around(0), 0b00000000);
assert_eq!(bitline.around(1), 0b00010100);
assert_eq!(bitline.around(2), 0b00110110);

let bitline = 0b00000000 as Bitline8;
assert_eq!(bitline.around(0), 0b00000000);
assert_eq!(bitline.around(1), 0b00000000);
assert_eq!(bitline.around(2), 0b00000000);
source

fn with_around(&self, n: usize) -> Self

Return all bits standing between n distance from the standing bits (with original standing bits).

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b00001000 as Bitline8;
assert_eq!(bitline.with_around(0), 0b00001000);
assert_eq!(bitline.with_around(1), 0b00011100);
assert_eq!(bitline.with_around(2), 0b00111110);

let bitline = 0b00000000 as Bitline8;
assert_eq!(bitline.with_around(0), 0b00000000);
assert_eq!(bitline.with_around(1), 0b00000000);
assert_eq!(bitline.with_around(2), 0b00000000);
source

fn first_bit(&self) -> Self

Return the first bit from the most significant bit. (last bit from the least significant bit)

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01001000_u8;
assert_eq!(bitline.first_bit(), 0b01000000_u8);
let bitline = 0b00000000_u8;
assert_eq!(bitline.first_bit(), 0b00000000_u8);
source

fn last_bit(&self) -> Self

Return the last bit from the most significant bit. (first bit from the least significant bit)

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01001000_u8;
assert_eq!(bitline.last_bit(), 0b00001000_u8);
let bitline = 0b00000000_u8;
assert_eq!(bitline.last_bit(), 0b00000000_u8);
source

fn first_bits(&self) -> Self

Return the first bits of each consecutive bits.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert_eq!(bitline.first_bits(), 0b01001000_u8);
let bitline = 0b00000000_u8;
assert_eq!(bitline.first_bits(), 0b00000000_u8);
source

fn last_bits(&self) -> Self

Return the last bits of each consecutive bits.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert_eq!(bitline.last_bits(), 0b00100100_u8);
let bitline = 0b00000000_u8;
assert_eq!(bitline.last_bits(), 0b00000000_u8);
source

fn filled_first_bit_to_last_bit(&self) -> Self

Return the bits filled from the first bit to the last bit.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01000100_u8;
assert_eq!(bitline.filled_first_bit_to_last_bit(), 0b01111100_u8);
let bitline = 0b00000000_u8;
assert_eq!(bitline.filled_first_bit_to_last_bit(), 0b00000000_u8);
source

fn bytes_length() -> usize

Return the bytes size of the bitline.

Examples
use bittersweet::bitline::{Bitline, Bitline8, Bitline16, Bitline32, Bitline64};
assert_eq!(Bitline8::bytes_length(), 1);
assert_eq!(Bitline16::bytes_length(), 2);
assert_eq!(Bitline32::bytes_length(), 4);
assert_eq!(Bitline64::bytes_length(), 8);
source

fn length() -> usize

Return the bits size of the bitline.

Examples
use bittersweet::bitline::{Bitline, Bitline8, Bitline16, Bitline32, Bitline64};
assert_eq!(Bitline8::length(), 8);
assert_eq!(Bitline16::length(), 16);
assert_eq!(Bitline32::length(), 32);
assert_eq!(Bitline64::length(), 64);
source

fn num_bits(&self) -> usize

Return the bits standing in the given range. (bit count)

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert_eq!(bitline.num_bits(), 4);
let bitline = 0b00000000_u8;
assert_eq!(bitline.num_bits(), 0);
source

fn includes(&self, other: Self) -> bool

Return true if every bits are standing in the given standing bits. empty bitlines are always included. (like a empty set in a set)

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert!(bitline.includes(0b01100000_u8));
assert!(!bitline.includes(0b01100001_u8));
assert!(bitline.includes(0b00000000_u8));

let bitline = 0b00000000_u8;
assert!(bitline.includes(0b00000000_u8));
assert!(!bitline.includes(0b00000001_u8));
source

fn overlaps(&self, other: Self) -> bool

Return true if some bits are standing in the given standing bits.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert!(bitline.overlaps(0b01100000_u8));
assert!(!bitline.overlaps(0b00000001_u8));
assert!(!bitline.overlaps(0b00000000_u8));
source

fn range(&self, begin: usize, end: usize) -> Self

Return the standing bits by the given range.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert_eq!(bitline.range(0, 4), 0b01100000_u8);
assert_eq!(bitline.range(4, 8), 0b00001100_u8);
source

fn remove(&self, other: Self) -> Self

Return the standing bits not included by the given range.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
let bitline = 0b01101100_u8;
assert_eq!(bitline.remove(0b01100000_u8), 0b00001100_u8);
assert_eq!(bitline.remove(0b00001100_u8), 0b01100000_u8);
source

fn bit_repr(&self) -> String

Return the string representation of the bitline.

Examples
use bittersweet::bitline::{Bitline, Bitline8};
assert_eq!(0b01101100_u8.bit_repr(), "01101100");

Implementors§