1 // Copyright 2013 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 #![allow(missing_docs)]
14 //! Contains struct definitions for the layout of compiler built-in types.
16 //! They can be used as targets of transmutes in unsafe code for manipulating
17 //! the raw representations directly.
19 //! Their definition should always match the ABI defined in `rustc::back::abi`.
25 /// The representation of a Rust slice
32 impl<T> Copy for Slice<T> {}
34 /// The representation of a Rust closure
42 /// The representation of a Rust trait object.
44 /// This struct does not have a `Repr` implementation
45 /// because there is no way to refer to all trait objects generically.
48 pub struct TraitObject {
53 /// This trait is meant to map equivalences between raw structs and their
54 /// corresponding rust values.
55 pub trait Repr<T> for Sized? {
56 /// This function "unwraps" a rust value (without consuming it) into its raw
57 /// struct representation. This can be used to read/write different values
58 /// for the struct. This is a safe method because by default it does not
59 /// enable write-access to the fields of the return value in safe code.
61 fn repr(&self) -> T { unsafe { mem::transmute_copy(&self) } }
64 impl<T> Repr<Slice<T>> for [T] {}
65 impl Repr<Slice<u8>> for str {}