forked from ferrilab/bitvec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforeign_order.rs
More file actions
38 lines (32 loc) · 934 Bytes
/
foreign_order.rs
File metadata and controls
38 lines (32 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*! Third-party crates should be able to implement [`BitOrder`] usefully.
This test ensures that [`bitvec`] provides a sufficient API to implement
[`BitOrder`] in foreign crates and have these orderings work in the `bitvec`
system as peers of the provided orderings.
!*/
extern crate bitvec;
use bitvec::{
index::{
BitIdx,
BitPos,
},
mem::BitRegister,
prelude::*,
};
pub struct Swizzle;
unsafe impl BitOrder for Swizzle {
fn at<R>(index: BitIdx<R>) -> BitPos<R>
where R: BitRegister {
match R::BITS {
8 => BitPos::new(index.into_inner() ^ 0b100).unwrap(),
16 => BitPos::new(index.into_inner() ^ 0b1100).unwrap(),
32 => BitPos::new(index.into_inner() ^ 0b11100).unwrap(),
64 => BitPos::new(index.into_inner() ^ 0b111100).unwrap(),
_ => unreachable!("No other integers are supported"),
}
}
}
#[test]
#[cfg(not(miri))]
fn check_impl() {
bitvec::order::verify::<Swizzle>(cfg!(feature = "testing"));
}