Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
32881893
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,发现更多精彩内容 >>
提交
32881893
编写于
2月 18, 2017
作者:
D
Djzin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
impl RangeArgument for RangeInclusive and add appropriate tests
上级
3c97cbe4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
90 addition
and
1 deletion
+90
-1
src/libcollections/range.rs
src/libcollections/range.rs
+17
-1
src/libcollectionstest/btree/map.rs
src/libcollectionstest/btree/map.rs
+27
-0
src/libcollectionstest/lib.rs
src/libcollectionstest/lib.rs
+1
-0
src/libcollectionstest/vec.rs
src/libcollectionstest/vec.rs
+45
-0
未找到文件。
src/libcollections/range.rs
浏览文件 @
32881893
...
...
@@ -14,7 +14,7 @@
//! Range syntax.
use
core
::
ops
::{
RangeFull
,
Range
,
RangeTo
,
RangeFrom
};
use
core
::
ops
::{
RangeFull
,
Range
,
RangeTo
,
RangeFrom
,
RangeInclusive
};
use
Bound
::{
self
,
Excluded
,
Included
,
Unbounded
};
/// **RangeArgument** is implemented by Rust's built-in range types, produced
...
...
@@ -105,6 +105,22 @@ fn end(&self) -> Bound<&T> {
}
}
#[unstable(feature
=
"inclusive_range"
,
reason
=
"recently added, follows RFC"
,
issue
=
"28237"
)]
impl
<
T
>
RangeArgument
<
T
>
for
RangeInclusive
<
T
>
{
fn
start
(
&
self
)
->
Bound
<&
T
>
{
match
*
self
{
RangeInclusive
::
Empty
{
ref
at
}
=>
Included
(
at
),
RangeInclusive
::
NonEmpty
{
ref
start
,
..
}
=>
Included
(
start
),
}
}
fn
end
(
&
self
)
->
Bound
<&
T
>
{
match
*
self
{
RangeInclusive
::
Empty
{
ref
at
}
=>
Excluded
(
at
),
RangeInclusive
::
NonEmpty
{
ref
end
,
..
}
=>
Included
(
end
),
}
}
}
impl
<
T
>
RangeArgument
<
T
>
for
(
Bound
<
T
>
,
Bound
<
T
>
)
{
fn
start
(
&
self
)
->
Bound
<&
T
>
{
match
*
self
{
...
...
src/libcollectionstest/btree/map.rs
浏览文件 @
32881893
...
...
@@ -178,6 +178,33 @@ fn test_range_small() {
assert_eq!
(
j
,
size
-
2
);
}
#[test]
fn
test_range_inclusive
()
{
let
size
=
500
;
let
map
:
BTreeMap
<
_
,
_
>
=
(
0
...
size
)
.map
(|
i
|
(
i
,
i
))
.collect
();
fn
check
<
'a
,
L
,
R
>
(
lhs
:
L
,
rhs
:
R
)
where
L
:
IntoIterator
<
Item
=
(
&
'a
i32
,
&
'a
i32
)
>
,
R
:
IntoIterator
<
Item
=
(
&
'a
i32
,
&
'a
i32
)
>
,
{
let
lhs
:
Vec
<
_
>
=
lhs
.into_iter
()
.collect
();
let
rhs
:
Vec
<
_
>
=
rhs
.into_iter
()
.collect
();
assert_eq!
(
lhs
,
rhs
);
}
check
(
map
.range
(
size
+
1
...
size
+
1
),
vec!
[]);
check
(
map
.range
(
size
...
size
),
vec!
[(
&
size
,
&
size
)]);
check
(
map
.range
(
size
...
size
+
1
),
vec!
[(
&
size
,
&
size
)]);
check
(
map
.range
(
0
...
0
),
vec!
[(
&
0
,
&
0
)]);
check
(
map
.range
(
0
...
size
-
1
),
map
.range
(
..
size
));
check
(
map
.range
(
-
1
...-
1
),
vec!
[]);
check
(
map
.range
(
-
1
...
size
),
map
.range
(
..
));
check
(
map
.range
(
5
...
8
),
vec!
[(
&
5
,
&
5
),
(
&
6
,
&
6
),
(
&
7
,
&
7
),
(
&
8
,
&
8
)]);
check
(
map
.range
(
-
1
...
0
),
vec!
[(
&
0
,
&
0
)]);
check
(
map
.range
(
-
1
...
2
),
vec!
[(
&
0
,
&
0
),
(
&
1
,
&
1
),
(
&
2
,
&
2
)]);
}
#[test]
fn
test_range_equal_empty_cases
()
{
let
map
:
BTreeMap
<
_
,
_
>
=
(
0
..
5
)
.map
(|
i
|
(
i
,
i
))
.collect
();
...
...
src/libcollectionstest/lib.rs
浏览文件 @
32881893
...
...
@@ -14,6 +14,7 @@
#![feature(binary_heap_peek_mut_pop)]
#![feature(box_syntax)]
#![feature(btree_range)]
#![feature(inclusive_range_syntax)]
#![feature(collection_placement)]
#![feature(collections)]
#![feature(collections_bound)]
...
...
src/libcollectionstest/vec.rs
浏览文件 @
32881893
...
...
@@ -507,6 +507,51 @@ fn test_drain_range() {
assert_eq!
(
v
,
&
[(),
()]);
}
#[test]
fn
test_drain_inclusive_range
()
{
let
mut
v
=
vec!
[
'a'
,
'b'
,
'c'
,
'd'
,
'e'
];
for
_
in
v
.drain
(
1
...
3
)
{
}
assert_eq!
(
v
,
&
[
'a'
,
'e'
]);
let
mut
v
:
Vec
<
_
>
=
(
0
...
5
)
.map
(|
x
|
x
.to_string
())
.collect
();
for
_
in
v
.drain
(
1
...
5
)
{
}
assert_eq!
(
v
,
&
[
"0"
.to_string
()]);
let
mut
v
:
Vec
<
String
>
=
(
0
...
5
)
.map
(|
x
|
x
.to_string
())
.collect
();
for
_
in
v
.drain
(
0
...
5
)
{
}
assert_eq!
(
v
,
Vec
::
<
String
>
::
new
());
let
mut
v
:
Vec
<
_
>
=
(
0
...
5
)
.map
(|
x
|
x
.to_string
())
.collect
();
for
_
in
v
.drain
(
0
...
3
)
{
}
assert_eq!
(
v
,
&
[
"4"
.to_string
(),
"5"
.to_string
()]);
}
#[test]
fn
test_drain_max_vec_size
()
{
let
mut
v
=
Vec
::
<
()
>
::
with_capacity
(
usize
::
max_value
());
unsafe
{
v
.set_len
(
usize
::
max_value
());
}
for
_
in
v
.drain
(
usize
::
max_value
()
-
1
..
)
{
}
assert_eq!
(
v
.len
(),
usize
::
max_value
()
-
1
);
let
mut
v
=
Vec
::
<
()
>
::
with_capacity
(
usize
::
max_value
());
unsafe
{
v
.set_len
(
usize
::
max_value
());
}
for
_
in
v
.drain
(
usize
::
max_value
()
-
1
...
usize
::
max_value
()
-
1
)
{
}
assert_eq!
(
v
.len
(),
usize
::
max_value
()
-
1
);
}
#[test]
#[should_panic]
fn
test_drain_inclusive_out_of_bounds
()
{
let
mut
v
=
vec!
[
1
,
2
,
3
,
4
,
5
];
v
.drain
(
5
...
5
);
}
#[test]
fn
test_into_boxed_slice
()
{
let
xs
=
vec!
[
1
,
2
,
3
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录