]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // Copyright 2015 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 | // test that ordinary fat pointer operations work. | |
12 | ||
92a42be0 SL |
13 | struct Wrapper<T: ?Sized>(u32, T); |
14 | ||
15 | struct FatPtrContainer<'a> { | |
16 | ptr: &'a [u8] | |
17 | } | |
18 | ||
92a42be0 SL |
19 | fn fat_ptr_project(a: &Wrapper<[u8]>) -> &[u8] { |
20 | &a.1 | |
21 | } | |
22 | ||
92a42be0 SL |
23 | fn fat_ptr_simple(a: &[u8]) -> &[u8] { |
24 | a | |
25 | } | |
26 | ||
92a42be0 SL |
27 | fn fat_ptr_via_local(a: &[u8]) -> &[u8] { |
28 | let x = a; | |
29 | x | |
30 | } | |
31 | ||
92a42be0 SL |
32 | fn fat_ptr_from_struct(s: FatPtrContainer) -> &[u8] { |
33 | s.ptr | |
34 | } | |
35 | ||
92a42be0 SL |
36 | fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer { |
37 | FatPtrContainer { ptr: a } | |
38 | } | |
39 | ||
92a42be0 SL |
40 | fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) { |
41 | *b = a; | |
42 | } | |
43 | ||
9cc50fc6 SL |
44 | fn fat_ptr_constant() -> &'static str { |
45 | "HELLO" | |
46 | } | |
47 | ||
92a42be0 SL |
48 | fn main() { |
49 | let a = Wrapper(4, [7,6,5]); | |
50 | ||
51 | let p = fat_ptr_project(&a); | |
52 | let p = fat_ptr_simple(p); | |
53 | let p = fat_ptr_via_local(p); | |
54 | let p = fat_ptr_from_struct(fat_ptr_to_struct(p)); | |
55 | ||
56 | let mut target : &[u8] = &[42]; | |
57 | fat_ptr_store_to(p, &mut target); | |
58 | assert_eq!(target, &a.1); | |
9cc50fc6 SL |
59 | |
60 | assert_eq!(fat_ptr_constant(), "HELLO"); | |
92a42be0 | 61 | } |