Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
47576313
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
47576313
编写于
9月 18, 2013
作者:
J
Jimmy Zelinskie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove and replace cond! Closes #9282.
上级
adb638f5
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
55 addition
and
137 deletion
+55
-137
src/libextra/num/bigint.rs
src/libextra/num/bigint.rs
+2
-2
src/libstd/char.rs
src/libstd/char.rs
+12
-12
src/libstd/num/f32.rs
src/libstd/num/f32.rs
+18
-18
src/libstd/num/f64.rs
src/libstd/num/f64.rs
+18
-18
src/libstd/num/uint_macros.rs
src/libstd/num/uint_macros.rs
+5
-5
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+0
-36
src/test/run-pass/cond-macro-no-default.rs
src/test/run-pass/cond-macro-no-default.rs
+0
-23
src/test/run-pass/cond-macro.rs
src/test/run-pass/cond-macro.rs
+0
-23
未找到文件。
src/libextra/num/bigint.rs
浏览文件 @
47576313
...
...
@@ -115,8 +115,8 @@ fn cmp(&self, other: &BigUint) -> Ordering {
if
s_len
>
o_len
{
return
Greater
;
}
for
(
&
self_i
,
&
other_i
)
in
self
.data
.rev_iter
()
.zip
(
other
.data
.rev_iter
())
{
cond!
((
self_i
<
other_i
)
{
return
Less
;
}
(
self_i
>
other_i
)
{
return
Greater
;
})
if
self_i
<
other_i
{
return
Less
;
}
if
self_i
>
other_i
{
return
Greater
;
}
}
return
Equal
;
}
...
...
src/libstd/char.rs
浏览文件 @
47576313
...
...
@@ -281,11 +281,11 @@ pub fn escape_unicode(c: char, f: &fn(char)) {
// avoid calling str::to_str_radix because we don't really need to allocate
// here.
f
(
'\\'
);
let
pad
=
cond!
(
(
c
<=
'\xff'
)
{
f
(
'x'
);
2
}
(
c
<=
'\uffff'
)
{
f
(
'u'
);
4
}
_
{
f
(
'U'
);
8
}
)
;
let
pad
=
match
()
{
_
if
c
<=
'\xff'
=>
{
f
(
'x'
);
2
}
_
if
c
<=
'\uffff'
=>
{
f
(
'u'
);
4
}
_
=>
{
f
(
'U'
);
8
}
}
;
for
offset
in
range_step
::
<
i32
>
(
4
*
(
pad
-
1
),
-
1
,
-
4
)
{
unsafe
{
match
((
c
as
i32
)
>>
offset
)
&
0xf
{
...
...
@@ -329,13 +329,13 @@ pub fn len_utf8_bytes(c: char) -> uint {
static
MAX_FOUR_B
:
uint
=
2097152u
;
let
code
=
c
as
uint
;
cond!
(
(
code
<
MAX_ONE_B
)
{
1u
}
(
code
<
MAX_TWO_B
)
{
2u
}
(
code
<
MAX_THREE_B
)
{
3u
}
(
code
<
MAX_FOUR_B
)
{
4u
}
_
{
fail!
(
"invalid character!"
)
}
)
match
()
{
_
if
code
<
MAX_ONE_B
=>
1u
,
_
if
code
<
MAX_TWO_B
=>
2u
,
_
if
code
<
MAX_THREE_B
=>
3u
,
_
if
code
<
MAX_FOUR_B
=>
4u
,
_
=>
fail
!
(
"invalid character!"
),
}
}
impl
ToStr
for
char
{
...
...
src/libstd/num/f32.rs
浏览文件 @
47576313
...
...
@@ -206,35 +206,35 @@ impl Orderable for f32 {
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn
min
(
&
self
,
other
:
&
f32
)
->
f32
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
other
.is_NaN
())
{
*
other
}
(
*
self
<
*
other
)
{
*
self
}
_
{
*
other
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
other
.is_NaN
()
=>
*
other
,
_
if
*
self
<
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn
max
(
&
self
,
other
:
&
f32
)
->
f32
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
other
.is_NaN
())
{
*
other
}
(
*
self
>
*
other
)
{
*
self
}
_
{
*
other
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
other
.is_NaN
()
=>
*
other
,
_
if
*
self
>
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns the number constrained within the range `mn <= self <= mx`.
/// If any of the numbers are `NaN` then `NaN` is returned.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
f32
,
mx
:
&
f32
)
->
f32
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
!
(
*
self
<=
*
mx
))
{
*
mx
}
(
!
(
*
self
>=
*
mn
))
{
*
mn
}
_
{
*
self
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
!
(
*
self
<=
*
mx
)
=>
*
mx
,
_
if
!
(
*
self
>=
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
...
...
src/libstd/num/f64.rs
浏览文件 @
47576313
...
...
@@ -229,35 +229,35 @@ impl Orderable for f64 {
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn
min
(
&
self
,
other
:
&
f64
)
->
f64
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
other
.is_NaN
())
{
*
other
}
(
*
self
<
*
other
)
{
*
self
}
_
{
*
other
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
other
.is_NaN
()
=>
*
other
,
_
if
*
self
<
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns `NaN` if either of the numbers are `NaN`.
#[inline]
fn
max
(
&
self
,
other
:
&
f64
)
->
f64
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
other
.is_NaN
())
{
*
other
}
(
*
self
>
*
other
)
{
*
self
}
_
{
*
other
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
other
.is_NaN
()
=>
*
other
,
_
if
*
self
>
*
other
=>
*
self
,
_
=>
*
other
,
}
}
/// Returns the number constrained within the range `mn <= self <= mx`.
/// If any of the numbers are `NaN` then `NaN` is returned.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
f64
,
mx
:
&
f64
)
->
f64
{
cond!
(
(
self
.is_NaN
())
{
*
self
}
(
!
(
*
self
<=
*
mx
))
{
*
mx
}
(
!
(
*
self
>=
*
mn
))
{
*
mn
}
_
{
*
self
}
)
match
()
{
_
if
self
.is_NaN
()
=>
*
self
,
_
if
!
(
*
self
<=
*
mx
)
=>
*
mx
,
_
if
!
(
*
self
>=
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
...
...
src/libstd/num/uint_macros.rs
浏览文件 @
47576313
...
...
@@ -70,11 +70,11 @@ fn max(&self, other: &$T) -> $T {
/// Returns the number constrained within the range `mn <= self <= mx`.
#[inline]
fn
clamp
(
&
self
,
mn
:
&
$T
,
mx
:
&
$T
)
->
$T
{
cond!
(
(
*
self
>
*
mx
)
{
*
mx
}
(
*
self
<
*
mn
)
{
*
mn
}
_
{
*
self
}
)
match
()
{
_
if
(
*
self
>
*
mx
)
=>
*
mx
,
_
if
(
*
self
<
*
mn
)
=>
*
mn
,
_
=>
*
self
,
}
}
}
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
47576313
...
...
@@ -898,42 +898,6 @@ mod $c {
}
)
//
// A scheme-style conditional that helps to improve code clarity in some instances when
// the `if`, `else if`, and `else` keywords obscure predicates undesirably.
//
// # Example
//
// ~~~
// let clamped =
// if x > mx { mx }
// else if x < mn { mn }
// else { x };
// ~~~
//
// Using `cond!`, the above could be written as:
//
// ~~~
// let clamped = cond!(
// (x > mx) { mx }
// (x < mn) { mn }
// _ { x }
// );
// ~~~
//
// The optional default case is denoted by `_`.
//
macro_rules! cond (
( $(($pred:expr) $body:block)+ _ $default:block ) => (
$(if $pred $body else)+
$default
);
// for if the default case was ommitted
( $(($pred:expr) $body:block)+ ) => (
$(if $pred $body)else+
);
)
// NOTE(acrichto): start removing this after the next snapshot
macro_rules! printf (
($arg:expr) => (
...
...
src/test/run-pass/cond-macro-no-default.rs
已删除
100644 → 0
浏览文件 @
adb638f5
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn
clamp
<
T
:
Ord
+
Signed
>
(
x
:
T
,
mn
:
T
,
mx
:
T
)
->
T
{
cond!
(
(
x
>
mx
)
{
return
mx
;
}
(
x
<
mn
)
{
return
mn
;
}
)
return
x
;
}
fn
main
()
{
assert_eq!
(
clamp
(
1
,
2
,
4
),
2
);
assert_eq!
(
clamp
(
8
,
2
,
4
),
4
);
assert_eq!
(
clamp
(
3
,
2
,
4
),
3
);
}
src/test/run-pass/cond-macro.rs
已删除
100644 → 0
浏览文件 @
adb638f5
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn
clamp
<
T
:
Ord
+
Signed
>
(
x
:
T
,
mn
:
T
,
mx
:
T
)
->
T
{
cond!
(
(
x
>
mx
)
{
mx
}
(
x
<
mn
)
{
mn
}
_
{
x
}
)
}
fn
main
()
{
assert_eq!
(
clamp
(
1
,
2
,
4
),
2
);
assert_eq!
(
clamp
(
8
,
2
,
4
),
4
);
assert_eq!
(
clamp
(
3
,
2
,
4
),
3
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录