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.
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.
11 // test that ordinary fat pointer operations work.
13 struct Wrapper
<T
: ?Sized
>(u32, T
);
15 struct FatPtrContainer
<'a
> {
19 fn fat_ptr_project(a
: &Wrapper
<[u8]>) -> &[u8] {
23 fn fat_ptr_simple(a
: &[u8]) -> &[u8] {
27 fn fat_ptr_via_local(a
: &[u8]) -> &[u8] {
32 fn fat_ptr_from_struct(s
: FatPtrContainer
) -> &[u8] {
36 fn fat_ptr_to_struct(a
: &[u8]) -> FatPtrContainer
{
37 FatPtrContainer { ptr: a }
40 fn fat_ptr_store_to
<'a
>(a
: &'a
[u8], b
: &mut &'a
[u8]) {
44 fn fat_ptr_constant() -> &'
static str {
49 let a
= Wrapper(4, [7,6,5]);
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
));
56 let mut target
: &[u8] = &[42];
57 fat_ptr_store_to(p
, &mut target
);
58 assert_eq
!(target
, &a
.1);
60 assert_eq
!(fat_ptr_constant(), "HELLO");