Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5c2e9b29
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,发现更多精彩内容 >>
提交
5c2e9b29
编写于
4月 20, 2013
作者:
H
Huon Wilson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libcore: wrappers for size/align_of to act on values without needing explicit ::<type> annotations
上级
8b3c09a1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
57 addition
and
1 deletion
+57
-1
src/libcore/sys.rs
src/libcore/sys.rs
+57
-1
未找到文件。
src/libcore/sys.rs
浏览文件 @
5c2e9b29
...
...
@@ -83,12 +83,24 @@ pub fn get_type_desc<T>() -> *TypeDesc {
unsafe
{
rusti
::
get_tydesc
::
<
T
>
()
as
*
TypeDesc
}
}
/// Returns a pointer to a type descriptor.
#[inline(always)]
pub
fn
get_type_desc_val
<
T
>
(
_
val
:
&
T
)
->
*
TypeDesc
{
get_type_desc
::
<
T
>
()
}
/// Returns the size of a type
#[inline(always)]
pub
fn
size_of
<
T
>
()
->
uint
{
unsafe
{
rusti
::
size_of
::
<
T
>
()
}
}
/// Returns the size of the type that `_val` points to
#[inline(always)]
pub
fn
size_of_val
<
T
>
(
_
val
:
&
T
)
->
uint
{
size_of
::
<
T
>
()
}
/**
* Returns the size of a type, or 1 if the actual size is zero.
*
...
...
@@ -100,6 +112,13 @@ pub fn nonzero_size_of<T>() -> uint {
if
s
==
0
{
1
}
else
{
s
}
}
/// Returns the size of the type of the value that `_val` points to
#[inline(always)]
pub
fn
nonzero_size_of_val
<
T
>
(
_
val
:
&
T
)
->
uint
{
nonzero_size_of
::
<
T
>
()
}
/**
* Returns the ABI-required minimum alignment of a type
*
...
...
@@ -111,12 +130,26 @@ pub fn min_align_of<T>() -> uint {
unsafe
{
rusti
::
min_align_of
::
<
T
>
()
}
}
/// Returns the ABI-required minimum alignment of the type of the value that
/// `_val` points to
#[inline(always)]
pub
fn
min_align_of_val
<
T
>
(
_
val
:
&
T
)
->
uint
{
min_align_of
::
<
T
>
()
}
/// Returns the preferred alignment of a type
#[inline(always)]
pub
fn
pref_align_of
<
T
>
()
->
uint
{
unsafe
{
rusti
::
pref_align_of
::
<
T
>
()
}
}
/// Returns the preferred alignment of the type of the value that
/// `_val` points to
#[inline(always)]
pub
fn
pref_align_of_val
<
T
>
(
_
val
:
&
T
)
->
uint
{
pref_align_of
::
<
T
>
()
}
/// Returns the refcount of a shared box (as just before calling this)
#[inline(always)]
pub
fn
refcount
<
T
>
(
t
:
@
T
)
->
uint
{
...
...
@@ -162,7 +195,7 @@ pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! {
#[cfg(test)]
mod
tests
{
use
cast
;
use
sys
::
{
Closure
,
pref_align_of
,
size_of
,
nonzero_size_of
}
;
use
sys
::
*
;
#[test]
fn
size_of_basic
()
{
...
...
@@ -188,6 +221,14 @@ fn size_of_64() {
assert
!
(
size_of
::
<*
uint
>
()
==
8u
);
}
#[test]
fn
size_of_val_basic
()
{
assert_eq!
(
size_of_val
(
&
1u8
),
1
);
assert_eq!
(
size_of_val
(
&
1u16
),
2
);
assert_eq!
(
size_of_val
(
&
1u32
),
4
);
assert_eq!
(
size_of_val
(
&
1u64
),
8
);
}
#[test]
fn
nonzero_size_of_basic
()
{
type
Z
=
[
i8
,
..
0
];
...
...
@@ -196,6 +237,14 @@ fn nonzero_size_of_basic() {
assert
!
(
nonzero_size_of
::
<
uint
>
()
==
size_of
::
<
uint
>
());
}
#[test]
fn
nonzero_size_of_val_basic
()
{
let
z
=
[
0u8
,
..
0
];
assert_eq!
(
size_of_val
(
&
z
),
0u
);
assert_eq!
(
nonzero_size_of_val
(
&
z
),
1u
);
assert_eq!
(
nonzero_size_of_val
(
&
1u
),
size_of_val
(
&
1u
));
}
#[test]
fn
align_of_basic
()
{
assert
!
(
pref_align_of
::
<
u8
>
()
==
1u
);
...
...
@@ -219,6 +268,13 @@ fn align_of_64() {
assert
!
(
pref_align_of
::
<*
uint
>
()
==
8u
);
}
#[test]
fn
align_of_val_basic
()
{
assert_eq!
(
pref_align_of_val
(
&
1u8
),
1u
);
assert_eq!
(
pref_align_of_val
(
&
1u16
),
2u
);
assert_eq!
(
pref_align_of_val
(
&
1u32
),
4u
);
}
#[test]
fn
synthesize_closure
()
{
unsafe
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录