]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-2989.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / issue-2989.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 trait methods {
12     fn to_bytes(&self) -> Vec<u8> ;
13 }
14
15 impl methods for () {
16     fn to_bytes(&self) -> Vec<u8> {
17         Vec::new()
18     }
19 }
20
21 // the position of this function is significant! - if it comes before methods
22 // then it works, if it comes after it then it doesn't!
23 fn to_bools(bitv: Storage) -> Vec<bool> {
24     range(0, 8).map(|i| {
25         let w = i / 64;
26         let b = i % 64;
27         let x = 1u64 & (bitv.storage[w] >> b);
28         x == 1u64
29     }).collect()
30 }
31
32 struct Storage { storage: Vec<u64> }
33
34 pub fn main() {
35     let bools = vec!(false, false, true, false, false, true, true, false);
36     let bools2 = to_bools(Storage{storage: vec!(0b01100100)});
37
38     for i in range(0u, 8) {
39         println!("{} => {} vs {}", i, bools[i], bools2[i]);
40     }
41
42     assert_eq!(bools, bools2);
43 }