Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fcf25ae8
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fcf25ae8
编写于
5月 08, 2014
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #14019 : brson/rust/docs, r=alexcrichton
Just small bits of polish.
上级
a990920c
2aa42533
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
47 deletion
+28
-47
src/libcore/cast.rs
src/libcore/cast.rs
+21
-43
src/libcore/cell.rs
src/libcore/cell.rs
+1
-1
src/libcore/ptr.rs
src/libcore/ptr.rs
+2
-0
src/libstd/lib.rs
src/libstd/lib.rs
+4
-3
未找到文件。
src/libcore/cast.rs
浏览文件 @
fcf25ae8
...
...
@@ -14,32 +14,6 @@
use
intrinsics
;
use
ptr
::
copy_nonoverlapping_memory
;
/// Casts the value at `src` to U. The two types must have the same length.
#[inline]
pub
unsafe
fn
transmute_copy
<
T
,
U
>
(
src
:
&
T
)
->
U
{
let
mut
dest
:
U
=
mem
::
uninit
();
let
dest_ptr
:
*
mut
u8
=
transmute
(
&
mut
dest
);
let
src_ptr
:
*
u8
=
transmute
(
src
);
copy_nonoverlapping_memory
(
dest_ptr
,
src_ptr
,
mem
::
size_of
::
<
U
>
());
dest
}
/**
* Move a thing into the void
*
* The forget function will take ownership of the provided value but neglect
* to run any required cleanup or memory-management operations on it.
*/
#[inline]
pub
unsafe
fn
forget
<
T
>
(
thing
:
T
)
{
intrinsics
::
forget
(
thing
);
}
/**
* Force-increment the reference count on a shared box. If used
* carelessly, this can leak the box.
*/
#[inline]
pub
unsafe
fn
bump_box_refcount
<
T
>
(
t
:
@
T
)
{
forget
(
t
);
}
/**
* Transform a value of one type into a value of another type.
* Both types must have the same size and alignment.
...
...
@@ -54,10 +28,29 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
* ```
*/
#[inline]
pub
unsafe
fn
transmute
<
L
,
G
>
(
thing
:
L
)
->
G
{
pub
unsafe
fn
transmute
<
T
,
U
>
(
thing
:
T
)
->
U
{
intrinsics
::
transmute
(
thing
)
}
/**
* Move a thing into the void
*
* The forget function will take ownership of the provided value but neglect
* to run any required cleanup or memory-management operations on it.
*/
#[inline]
pub
unsafe
fn
forget
<
T
>
(
thing
:
T
)
{
intrinsics
::
forget
(
thing
);
}
/// Casts the value at `src` to U. The two types must have the same length.
#[inline]
pub
unsafe
fn
transmute_copy
<
T
,
U
>
(
src
:
&
T
)
->
U
{
let
mut
dest
:
U
=
mem
::
uninit
();
let
dest_ptr
:
*
mut
u8
=
transmute
(
&
mut
dest
);
let
src_ptr
:
*
u8
=
transmute
(
src
);
copy_nonoverlapping_memory
(
dest_ptr
,
src_ptr
,
mem
::
size_of
::
<
U
>
());
dest
}
/// Coerce an immutable reference to be mutable.
#[inline]
#[deprecated=
"casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"
]
...
...
@@ -106,7 +99,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
#[cfg(test)]
mod
tests
{
use
cast
::
{
bump_box_refcount
,
transmute
}
;
use
cast
::
transmute
;
use
raw
;
use
realstd
::
str
::
StrAllocating
;
...
...
@@ -115,21 +108,6 @@ fn test_transmute_copy() {
assert_eq!
(
1u
,
unsafe
{
::
cast
::
transmute_copy
(
&
1
)
});
}
#[test]
fn
test_bump_managed_refcount
()
{
unsafe
{
let
managed
=
@
"box box box"
.to_owned
();
// refcount 1
bump_box_refcount
(
managed
);
// refcount 2
let
ptr
:
*
int
=
transmute
(
managed
);
// refcount 2
let
_
box1
:
@~
str
=
::
cast
::
transmute_copy
(
&
ptr
);
let
_
box2
:
@~
str
=
::
cast
::
transmute_copy
(
&
ptr
);
assert
!
(
*
_
box1
==
"box box box"
.to_owned
());
assert
!
(
*
_
box2
==
"box box box"
.to_owned
());
// Will destroy _box1 and _box2. Without the bump, this would
// use-after-free. With too many bumps, it would leak.
}
}
#[test]
fn
test_transmute
()
{
unsafe
{
...
...
src/libcore/cell.rs
浏览文件 @
fcf25ae8
...
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Types
dealing with dynamic mutability
//! Types
that provide interior mutability.
use
clone
::
Clone
;
use
cmp
::
Eq
;
...
...
src/libcore/ptr.rs
浏览文件 @
fcf25ae8
...
...
@@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// FIXME: talk about offset, copy_memory, copy_nonoverlapping_memory
//! Conveniences for working with unsafe pointers, the `*T`, and `*mut T` types.
//!
//! Working with unsafe pointers in Rust is fairly uncommon,
...
...
src/libstd/lib.rs
浏览文件 @
fcf25ae8
...
...
@@ -81,7 +81,7 @@
//! memory types, including [`atomics`](sync/atomics/index.html).
//!
//! Common types of I/O, including files, TCP, UPD, pipes, Unix domain sockets,
//! timers, and process spawning, are defined in the [`io`](io/index.html).
//! timers, and process spawning, are defined in the [`io`](io/index.html)
module
.
//!
//! Rust's I/O and concurrency depends on a small runtime interface
//! that lives, along with its support code, in mod [`rt`](rt/index.html).
...
...
@@ -90,10 +90,11 @@
//!
//! ## The Rust prelude and macros
//!
//! Finally, the [`prelude`](prelude/index.html) defines a
set of
//! Finally, the [`prelude`](prelude/index.html) defines a
//! common set of traits, types, and functions that are made available
//! to all code by default. [`macros`](macros/index.html) contains
//! all the standard macros, such as `assert!`, `fail!`, `println!`.
//! all the standard macros, such as `assert!`, `fail!`, `println!`,
//! and `format!`, also available to all Rust code.
#![crate_id
=
"std#0.11-pre"
]
#![comment
=
"The Rust standard library"
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录