(index<- ) ./libstd/unstable/raw.rs
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.
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 use cast;
12 use unstable::intrinsics::TyDesc;
13
14 /// The representation of a Rust managed box
15 pub struct Box<T> {
16 ref_count: uint,
17 type_desc: *TyDesc,
18 prev: *Box<T>,
19 next: *Box<T>,
20 data: T
21 }
22
23 /// The representation of a Rust vector
24 pub struct Vec<T> {
25 fill: uint,
26 alloc: uint,
27 data: T
28 }
29
30 /// The representation of a Rust string
31 pub type String = Vec<u8>;
32
33 /// The representation of a Rust slice
34 pub struct Slice<T> {
35 data: *T,
36 len: uint
37 }
38
39 /// The representation of a Rust closure
40 pub struct Closure {
41 code: *(),
42 env: *(),
43 }
44
45 /// This trait is meant to map equivalences between raw structs and their
46 /// corresponding rust values.
47 pub trait Repr<T> {
48 /// This function "unwraps" a rust value (without consuming it) into its raw
49 /// struct representation. This can be used to read/write different values
50 /// for the struct. This is a safe method because by default it does not
51 /// give write-access to the struct returned.
52 #[inline]
53 fn repr(&self) -> T { unsafe { cast::transmute_copy(self) } }
54 }
55
56 impl<'self, T> Repr<Slice<T>> for &'self [T] {}
57 impl<'self> Repr<Slice<u8>> for &'self str {}
58 impl<T> Repr<*Box<T>> for @T {}
59 impl<T> Repr<*Box<Vec<T>>> for @[T] {}
60 impl Repr<*String> for ~str {}
61 impl Repr<*Box<String>> for @str {}
62
63 // sure would be nice to have this
64 // impl<T> Repr<*Vec<T>> for ~[T] {}
libstd/unstable/raw.rs:46:31-46:31 -trait- definition:
/// corresponding rust values.
pub trait Repr<T> {
references:-58: impl<T> Repr<*Box<T>> for @T {}
60: impl Repr<*String> for ~str {}
57: impl<'self> Repr<Slice<u8>> for &'self str {}
61: impl Repr<*Box<String>> for @str {}
56: impl<'self, T> Repr<Slice<T>> for &'self [T] {}
59: impl<T> Repr<*Box<Vec<T>>> for @[T] {}
libstd/unstable/raw.rs:23:40-23:40 -struct- definition:
/// The representation of a Rust vector
pub struct Vec<T> {
references:-31: pub type String = Vec<u8>;
59: impl<T> Repr<*Box<Vec<T>>> for @[T] {}
libstd/vec.rs:
1410: let size = alloc + sys::size_of::<Vec<()>>();
1444: let repr: **Vec<()> = cast::transmute(self);
1452: let ptr: *mut *mut Vec<()> = cast::transmute(self);
1454: let size = alloc + sys::size_of::<Vec<()>>();
1455: *ptr = realloc_raw(*ptr as *mut c_void, size) as *mut Vec<()>;
1464: let repr: **Box<Vec<()>> = cast::transmute(&mut *self);
1408: let ptr: *mut *mut Vec<()> = cast::transmute(self);
1493: let repr: **mut Vec<u8> = cast::transmute(this);
1486: let repr: **mut Box<Vec<u8>> = cast::transmute(this);
2073: let repr: **mut Box<Vec<()>> = cast::transmute(v);
1405: let ptr: *mut *mut Box<Vec<()>> = cast::transmute(self);
189: let ptr = malloc_raw(alloc + sys::size_of::<Vec<()>>()) as *mut Vec<()>;
2076: let repr: **mut Vec<()> = cast::transmute(v);
1441: let repr: **Box<Vec<()>> = cast::transmute(self);
189: let ptr = malloc_raw(alloc + sys::size_of::<Vec<()>>()) as *mut Vec<()>;
1472: let repr: **Vec<()> = cast::transmute(&mut *self);
1415: as *mut Vec<()>;
libstd/at_vec.rs:
188: let repr: *Box<Vec<T>> = cast::transmute_copy(v);
234: pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
200: let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
178: let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
243: (*ptr) = local_realloc(*ptr as *(), total_size) as *mut Box<Vec<()>>;
239: let total_size = alloc + sys::size_of::<Vec<()>>();
226: let ptr: *mut *mut Box<Vec<()>> = transmute(v);
libstd/repr.rs:
211: pub fn write_unboxed_vec_repr(&mut self, _: uint, v: &raw::Vec<()>, inner: *TyDesc) -> bool {
349: do self.get::<&raw::Box<raw::Vec<()>>> |this, b| {
343: do self.get::<raw::Vec<()>> |this, b| {
364: do self.get::<&raw::Box<raw::Vec<()>>> |this, b| {
(357)libstd/reflect.rs:
(256)libstd/unstable/raw.rs:30:40-30:40 -ty- definition:
/// The representation of a Rust string
pub type String = Vec<u8>;
references:-61: impl Repr<*Box<String>> for @str {}
60: impl Repr<*String> for ~str {}
libstd/unstable/raw.rs:33:39-33:39 -struct- definition:
/// The representation of a Rust slice
pub struct Slice<T> {
references:-56: impl<'self, T> Repr<Slice<T>> for &'self [T] {}
57: impl<'self> Repr<Slice<u8>> for &'self str {}
libstd/vec.rs:
2016: let Slice{ data, len } = self.repr();
2123: f(cast::transmute(Slice {
2109: f(cast::transmute(Slice {
1928: cast::transmute(Slice {
983: cast::transmute(Slice {
libstd/str.rs:
1118: cast::transmute(Slice {
1090: let v = Slice { data: s, len: len };
libstd/rand/mod.rs:
139: let mut slice: Slice<u64> = unsafe { cast::transmute_copy(&dest) };
152: let mut slice: Slice<u32> = unsafe { cast::transmute_copy(&dest) };
libstd/repr.rs:
371: do self.get::<raw::Slice<()>> |this, s| {
libstd/unstable/raw.rs:14:45-14:45 -struct- definition:
/// The representation of a Rust managed box
pub struct Box<T> {
references:-61: impl Repr<*Box<String>> for @str {}
59: impl<T> Repr<*Box<Vec<T>>> for @[T] {}
18: prev: *Box<T>,
58: impl<T> Repr<*Box<T>> for @T {}
19: next: *Box<T>,
libstd/rt/global_heap.rs:
23: let header_size = size_of::<raw::Box<()>>();
87: let box = p as *mut raw::Box<()>;
libstd/rt/local_heap.rs:
28: live_allocs: *raw::Box<()>,
112: pub fn live_allocs() -> *raw::Box<()> {
libstd/rt/borrowck.rs:
196: let a = a as *mut raw::Box<()>;
122: let a = a as *mut raw::Box<()>;
32: box: *mut raw::Box<()>,
60: unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) {
158: let a = a as *mut raw::Box<()>;
212: let a = a as *mut raw::Box<()>;
139: let a = a as *mut raw::Box<()>;
173: let a = a as *mut raw::Box<()>;
libstd/vec.rs:
1441: let repr: **Box<Vec<()>> = cast::transmute(self);
1405: let ptr: *mut *mut Box<Vec<()>> = cast::transmute(self);
2073: let repr: **mut Box<Vec<()>> = cast::transmute(v);
1486: let repr: **mut Box<Vec<u8>> = cast::transmute(this);
1464: let repr: **Box<Vec<()>> = cast::transmute(&mut *self);
libstd/at_vec.rs:
178: let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
226: let ptr: *mut *mut Box<Vec<()>> = transmute(v);
243: (*ptr) = local_realloc(*ptr as *(), total_size) as *mut Box<Vec<()>>;
234: pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
188: let repr: *Box<Vec<T>> = cast::transmute_copy(v);
200: let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
libstd/repr.rs:
600: do self.get::<&raw::Box<()>> |this, b| {
317: do self.get::<&raw::Box<()>> |this, b| {
(349)(302)(364)libstd/cleanup.rs:
(33)(118)(44)libstd/unstable/raw.rs:39:41-39:41 -struct- definition:
/// The representation of a Rust closure
pub struct Closure {
references:-libstd/rt/task.rs:
427: let closure: Closure = transmute(f);
437: let closure: Closure = Closure {
437: let closure: Closure = Closure {
libstd/rt/sched.rs:
835: type UnsafeTaskReceiver = raw::Closure;
libstd/condition.rs:
75: priv handle: Closure,
108: let h: Closure = unsafe { ::cast::transmute(h) };