rust/src
Stepan Koltsov 5a722f8632 box: into_raw, from_raw functions
Functions are needed for safety and convenience.

It is a common pattern to use `mem::transmute` to convert between
`Box` and raw pointer, like this:

```
let b = Box::new(3);
let p = mem::transmute(b);
// pass `p` to some C library
```

After this commit, conversion can be written as:

```
let p = boxed::into_raw(b);
```

`into_raw` and `from_raw` functions are still unsafe, but they are
much safer than `mem::transmute`, because *raw functions do not
convert between incompatible pointers. For example, this likely
incorrect code can be successfully compiled:

```
let p: *mut u64 = ...
let b: Box<u32> = mem::transmute(p);
```

Using `from_raw` results in compile-time error:

```
let p: *mut u64 = ...
let b: Box<u32> = Box::from_raw(p); // compile-time error
```

`into_raw` and `from_raw` functions are similar to C++ `std::unique_ptr`
`release` function [1] and constructor from pointer [2].

[1] http://en.cppreference.com/w/cpp/memory/unique_ptr/release
[2] http://en.cppreference.com/w/cpp/memory/unique_ptr/unique_ptr
2015-02-01 20:15:44 +03:00
..
compiler-rt@58ab642c30
compiletest Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
doc Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
driver Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
etc rollup merge of #21738: steveklabnik/move_out_editors 2015-01-30 12:03:26 -08:00
grammar
jemalloc@b001609960
liballoc box: into_raw, from_raw functions 2015-02-01 20:15:44 +03:00
libarena Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libbacktrace
libcollections Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libcore remove Copy impls from remaining iterators 2015-01-31 09:09:22 -05:00
libcoretest Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libflate Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libfmt_macros Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libgetopts Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libgraphviz Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
liblibc Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
liblog Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librand Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librbml Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc Separate out the unboxed closure table into two tables, so that we can 2015-02-01 06:13:06 -05:00
librustc_back Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc_bitflags Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc_borrowck Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc_driver Merge remote-tracking branch 'origin/master' into rollup 2015-01-30 14:55:34 -08:00
librustc_llvm Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc_privacy Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
librustc_resolve Merge remote-tracking branch 'origin/master' into rollup 2015-01-30 14:55:34 -08:00
librustc_trans Separate out the unboxed closure table into two tables, so that we can 2015-02-01 06:13:06 -05:00
librustc_typeck Do not ICE when e.g. call_mut() is called on a closure whose kind is not yet known. 2015-02-01 06:13:07 -05:00
librustdoc Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libserialize Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libstd Auto merge of #21788 - carllerche:master, r=alexcrichton 2015-02-01 07:21:14 +00:00
libsyntax Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libterm Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libtest Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
libunicode Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
llvm@b820135911
rt
rust-installer@e577c97b49
rustbook rollup merge of #21494: jatinn/jsnav 2015-01-30 12:02:48 -08:00
rustllvm Test fixes and rebase conflicts 2015-01-30 14:53:34 -08:00
test Do not ICE when e.g. call_mut() is called on a closure whose kind is not yet known. 2015-02-01 06:13:07 -05:00
snapshots.txt Register snaps 2015-01-29 15:02:00 -08:00