2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2018-08-31 15:02:01 +02:00
|
|
|
#![allow(non_camel_case_types)]
|
|
|
|
|
|
2024-02-07 10:42:01 +08:00
|
|
|
trait methods { //~ WARN trait `methods` is never used
|
|
|
|
|
fn to_bytes(&self) -> Vec<u8>;
|
2012-09-01 14:09:57 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl methods for () {
|
2014-03-05 14:02:44 -08:00
|
|
|
fn to_bytes(&self) -> Vec<u8> {
|
2015-01-01 23:53:35 -08:00
|
|
|
Vec::new()
|
2012-09-01 14:09:57 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the position of this function is significant! - if it comes before methods
|
2013-05-09 02:34:47 +09:00
|
|
|
// then it works, if it comes after it then it doesn't!
|
2014-03-05 14:02:44 -08:00
|
|
|
fn to_bools(bitv: Storage) -> Vec<bool> {
|
2015-03-03 10:42:26 +02:00
|
|
|
(0..8).map(|i| {
|
2012-09-01 14:09:57 -07:00
|
|
|
let w = i / 64;
|
|
|
|
|
let b = i % 64;
|
2015-03-03 10:42:26 +02:00
|
|
|
let x = 1 & (bitv.storage[w] >> b);
|
|
|
|
|
x == 1
|
2015-01-01 23:53:35 -08:00
|
|
|
}).collect()
|
2012-09-01 14:09:57 -07:00
|
|
|
}
|
|
|
|
|
|
2014-03-05 14:02:44 -08:00
|
|
|
struct Storage { storage: Vec<u64> }
|
2013-01-25 22:46:32 -08:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2016-10-29 22:54:04 +01:00
|
|
|
let bools = vec![false, false, true, false, false, true, true, false];
|
|
|
|
|
let bools2 = to_bools(Storage{storage: vec![0b01100100]});
|
2012-09-01 14:09:57 -07:00
|
|
|
|
2015-03-03 10:42:26 +02:00
|
|
|
for i in 0..8 {
|
2014-10-14 23:05:01 -07:00
|
|
|
println!("{} => {} vs {}", i, bools[i], bools2[i]);
|
2012-09-01 14:09:57 -07:00
|
|
|
}
|
|
|
|
|
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(bools, bools2);
|
2012-10-12 12:32:36 -07:00
|
|
|
}
|