-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::{BitCountType, Wire}; | ||
|
||
use core::ops::{Index, IndexMut}; | ||
|
||
// Warning! Indexes by byte (not bit). This isn't very useful. | ||
impl<const B: BitCountType, const S: usize> Index<usize> for Wire<{B}, {S}> { | ||
type Output = u8; | ||
|
||
fn index(&self, idx: usize) -> &u8 { | ||
&self.repr[idx] | ||
} | ||
} | ||
|
||
impl<const B: BitCountType, const S: usize> IndexMut<usize> for Wire<{B}, {S}> { | ||
fn index_mut(&mut self, idx: usize) -> &mut u8 { | ||
&mut self.repr[idx] | ||
} | ||
} | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::w; | ||
|
||
#[test] | ||
fn index_bytes() { | ||
assert_eq!(w!(1#0)[0], 0u8); | ||
assert_eq!(w!(8*8)[7], 0u8); | ||
assert_eq!(w!((8*7)#core::u64::MAX)[7], 255u8); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
mod conversions; | ||
mod fmt; | ||
mod index; | ||
|
||
use core::mem::{size_of, MaybeUninit}; | ||
|
||
|