Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
66e5dfbd
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,发现更多精彩内容 >>
提交
66e5dfbd
编写于
4月 28, 2011
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stdlib: Provide "array" as a friendlier shorthand for "vec[mutable? T]"
上级
e300b804
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
17 deletion
+18
-17
src/lib/_vec.rs
src/lib/_vec.rs
+18
-17
未找到文件。
src/lib/_vec.rs
浏览文件 @
66e5dfbd
...
...
@@ -6,6 +6,8 @@
type
operator2
[
T
,
U
,
V
]
=
fn
(
&
T
,
&
U
)
->
V
;
type
array
[
T
]
=
vec
[
mutable
?
T
];
native
"rust"
mod
rustrt
{
type
vbuf
;
...
...
@@ -43,7 +45,7 @@ fn alloc_mut[T](uint n_elts) -> vec[mutable T] {
ret
rustrt
.vec_alloc_mut
[
vec
[
mutable
T
],
T
](
n_elts
);
}
fn
refcount
[
T
](
vec
[
mutable
?
T
]
v
)
->
uint
{
fn
refcount
[
T
](
array
[
T
]
v
)
->
uint
{
auto
r
=
rustrt
.refcount
[
T
](
v
);
if
(
r
==
dbg
.const_refcount
)
{
ret
r
;
...
...
@@ -116,29 +118,29 @@ fn init_elt_mut[T](&T t, uint n_elts) -> vec[mutable T] {
ret
v
;
}
fn
buf
[
T
](
vec
[
mutable
?
T
]
v
)
->
vbuf
{
fn
buf
[
T
](
array
[
T
]
v
)
->
vbuf
{
ret
rustrt
.vec_buf
[
T
](
v
,
0u
);
}
fn
len
[
T
](
vec
[
mutable
?
T
]
v
)
->
uint
{
fn
len
[
T
](
array
[
T
]
v
)
->
uint
{
ret
rustrt
.vec_len
[
T
](
v
);
}
fn
len_set
[
T
](
vec
[
mutable
?
T
]
v
,
uint
n
)
{
fn
len_set
[
T
](
array
[
T
]
v
,
uint
n
)
{
rustrt
.vec_len_set
[
T
](
v
,
n
);
}
fn
buf_off
[
T
](
vec
[
mutable
?
T
]
v
,
uint
offset
)
->
vbuf
{
fn
buf_off
[
T
](
array
[
T
]
v
,
uint
offset
)
->
vbuf
{
check
(
offset
<
len
[
T
](
v
));
ret
rustrt
.vec_buf
[
T
](
v
,
offset
);
}
fn
print_debug_info
[
T
](
vec
[
mutable
?
T
]
v
)
{
fn
print_debug_info
[
T
](
array
[
T
]
v
)
{
rustrt
.vec_print_debug_info
[
T
](
v
);
}
// Returns the last element of v.
fn
last
[
T
](
vec
[
mutable
?
T
]
v
)
->
option
.t
[
T
]
{
fn
last
[
T
](
array
[
T
]
v
)
->
option
.t
[
T
]
{
auto
l
=
len
[
T
](
v
);
if
(
l
==
0u
)
{
ret
none
[
T
];
...
...
@@ -147,7 +149,7 @@ fn last[T](vec[mutable? T] v) -> option.t[T] {
}
// Returns elements from [start..end) from v.
fn
slice
[
T
](
vec
[
mutable
?
T
]
v
,
uint
start
,
uint
end
)
->
vec
[
T
]
{
fn
slice
[
T
](
array
[
T
]
v
,
uint
start
,
uint
end
)
->
vec
[
T
]
{
check
(
start
<=
end
);
check
(
end
<=
len
[
T
](
v
));
auto
result
=
alloc
[
T
](
end
-
start
);
...
...
@@ -159,7 +161,7 @@ fn slice[T](vec[mutable? T] v, uint start, uint end) -> vec[T] {
ret
result
;
}
fn
shift
[
T
](
&
mutable
vec
[
mutable
?
T
]
v
)
->
T
{
fn
shift
[
T
](
&
mutable
array
[
T
]
v
)
->
T
{
auto
ln
=
len
[
T
](
v
);
check
(
ln
>
0u
);
auto
e
=
v
.
(
0
);
...
...
@@ -167,7 +169,7 @@ fn shift[T](&mutable vec[mutable? T] v) -> T {
ret
e
;
}
fn
pop
[
T
](
&
mutable
vec
[
mutable
?
T
]
v
)
->
T
{
fn
pop
[
T
](
&
mutable
array
[
T
]
v
)
->
T
{
auto
ln
=
len
[
T
](
v
);
check
(
ln
>
0u
);
ln
-=
1u
;
...
...
@@ -176,18 +178,18 @@ fn pop[T](&mutable vec[mutable? T] v) -> T {
ret
e
;
}
fn
push
[
T
](
&
mutable
vec
[
mutable
?
T
]
v
,
&
T
t
)
{
fn
push
[
T
](
&
mutable
array
[
T
]
v
,
&
T
t
)
{
v
+=
vec
(
t
);
}
fn
unshift
[
T
](
&
mutable
vec
[
mutable
?
T
]
v
,
&
T
t
)
{
fn
unshift
[
T
](
&
mutable
array
[
T
]
v
,
&
T
t
)
{
auto
res
=
alloc
[
T
](
len
[
T
](
v
)
+
1u
);
res
+=
vec
(
t
);
res
+=
v
;
v
=
res
;
}
fn
grow
[
T
](
&
mutable
vec
[
mutable
?
T
]
v
,
uint
n
,
&
T
initval
)
{
fn
grow
[
T
](
&
mutable
array
[
T
]
v
,
uint
n
,
&
T
initval
)
{
let
uint
i
=
n
;
while
(
i
>
0u
)
{
i
-=
1u
;
...
...
@@ -203,7 +205,7 @@ fn grow_set[T](&mutable vec[mutable T] v, uint index, &T initval, &T val) {
v
.
(
index
)
=
val
;
}
fn
map
[
T
,
U
](
&
option
.operator
[
T
,
U
]
f
,
&
vec
[
mutable
?
T
]
v
)
->
vec
[
U
]
{
fn
map
[
T
,
U
](
&
option
.operator
[
T
,
U
]
f
,
&
array
[
T
]
v
)
->
vec
[
U
]
{
let
vec
[
U
]
u
=
alloc
[
U
](
len
[
T
](
v
));
for
(
T
ve
in
v
)
{
u
+=
vec
(
f
(
ve
));
...
...
@@ -211,8 +213,7 @@ fn map[T, U](&option.operator[T,U] f, &vec[mutable? T] v) -> vec[U] {
ret
u
;
}
fn
map2
[
T
,
U
,
V
](
&
operator2
[
T
,
U
,
V
]
f
,
&
vec
[
mutable
?
T
]
v0
,
&
vec
[
mutable
?
U
]
v1
)
->
vec
[
V
]
{
fn
map2
[
T
,
U
,
V
](
&
operator2
[
T
,
U
,
V
]
f
,
&
array
[
T
]
v0
,
&
array
[
U
]
v1
)
->
vec
[
V
]
{
auto
v0_len
=
len
[
T
](
v0
);
if
(
v0_len
!=
len
[
U
](
v1
))
{
fail
;
...
...
@@ -228,7 +229,7 @@ fn map2[T,U,V](&operator2[T,U,V] f, &vec[mutable? T] v0, &vec[mutable? U] v1)
ret
u
;
}
fn
find
[
T
](
fn
(
&
T
)
->
bool
f
,
&
vec
[
mutable
?
T
]
v
)
->
option
.t
[
T
]
{
fn
find
[
T
](
fn
(
&
T
)
->
bool
f
,
&
array
[
T
]
v
)
->
option
.t
[
T
]
{
for
(
T
elt
in
v
)
{
if
(
f
(
elt
))
{
ret
some
[
T
](
elt
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录