Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
dbfa1b56
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
dbfa1b56
编写于
12月 16, 2011
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1317 from boggle/fix1315
fix to #1315 + small additions to std::either and result
上级
1bf078f9
7d786318
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
58 addition
and
25 deletion
+58
-25
src/libcore/bool.rs
src/libcore/bool.rs
+1
-1
src/libcore/box.rs
src/libcore/box.rs
+1
-1
src/libcore/char.rs
src/libcore/char.rs
+2
-2
src/libcore/either.rs
src/libcore/either.rs
+25
-0
src/libcore/option.rs
src/libcore/option.rs
+2
-2
src/libcore/result.rs
src/libcore/result.rs
+10
-3
src/libcore/str.rs
src/libcore/str.rs
+4
-4
src/libcore/sys.rs
src/libcore/sys.rs
+1
-1
src/libcore/vec.rs
src/libcore/vec.rs
+3
-3
src/libstd/bitv.rs
src/libstd/bitv.rs
+1
-1
src/libstd/list.rs
src/libstd/list.rs
+3
-3
src/libstd/posix_fs.rs
src/libstd/posix_fs.rs
+1
-0
src/libstd/rope.rs
src/libstd/rope.rs
+1
-1
src/libstd/unicode.rs
src/libstd/unicode.rs
+3
-3
未找到文件。
src/libcore/bool.rs
浏览文件 @
dbfa1b56
...
...
@@ -123,7 +123,7 @@ fn all_values(blk: block(v: t)) {
An u8 whose first bit is set if `if_true(v)` holds
*/
fn
to_bit
(
v
:
t
)
->
u8
{
if
v
{
1u8
}
else
{
0u8
}
}
pure
fn
to_bit
(
v
:
t
)
->
u8
{
if
v
{
1u8
}
else
{
0u8
}
}
// Local Variables:
// mode: rust;
...
...
src/libcore/box.rs
浏览文件 @
dbfa1b56
...
...
@@ -10,7 +10,7 @@
Determine if two shared boxes point to the same object
*/
fn
ptr_eq
<
T
>
(
a
:
@
T
,
b
:
@
T
)
->
bool
{
pure
fn
ptr_eq
<
T
>
(
a
:
@
T
,
b
:
@
T
)
->
bool
{
// FIXME: ptr::addr_of
unsafe
{
let
a_ptr
:
uint
=
unsafe
::
reinterpret_cast
(
a
);
...
...
src/libcore/char.rs
浏览文件 @
dbfa1b56
...
...
@@ -122,7 +122,7 @@
Convert a char to the corresponding digit. Returns none when the
character is not a valid hexadecimal digit.
*/
fn
maybe_digit
(
c
:
char
)
->
option
::
t
<
u8
>
{
pure
fn
maybe_digit
(
c
:
char
)
->
option
::
t
<
u8
>
{
alt
c
{
'0'
to
'9'
{
option
::
some
(
c
as
u8
-
(
'0'
as
u8
))
}
'a'
to
'z'
{
option
::
some
(
c
as
u8
+
10u8
-
(
'a'
as
u8
))
}
...
...
@@ -143,7 +143,7 @@ fn maybe_digit(c: char) -> option::t<u8> {
Returns:
-1 if a<b, 0 if a==b, +1 if a>b
*/
fn
cmp
(
a
:
char
,
b
:
char
)
->
int
{
pure
fn
cmp
(
a
:
char
,
b
:
char
)
->
int
{
ret
if
b
>
a
{
-
1
}
else
if
b
<
a
{
1
}
else
{
0
}
...
...
src/libcore/either.rs
浏览文件 @
dbfa1b56
...
...
@@ -78,6 +78,31 @@ fn partition<copy T, copy U>(eithers: [t<T, U>])
ret
{
lefts
:
lefts
,
rights
:
rights
};
}
/*
Function: flip
Flips between left and right of a given either
*/
pure
fn
flip
<
copy
T
,
copy
U
>
(
eith
:
t
<
T
,
U
>
)
->
t
<
U
,
T
>
{
alt
eith
{
right
(
r
)
{
left
(
r
)
}
left
(
l
)
{
right
(
l
)
}
}
}
/*
Function: to_result
Converts either::t to a result::t, making the "right" choice
an ok result, and the "left" choice a fail
*/
pure
fn
to_result
<
copy
T
,
copy
U
>
(
eith
:
t
<
T
,
U
>
)
->
result
::
t
<
U
,
T
>
{
alt
eith
{
right
(
r
)
{
result
::
ok
(
r
)
}
left
(
l
)
{
result
::
err
(
l
)
}
}
}
//
// Local Variables:
// mode: rust
...
...
src/libcore/option.rs
浏览文件 @
dbfa1b56
...
...
@@ -30,7 +30,7 @@
Fails if the value equals `none`.
*/
fn
get
<
copy
T
>
(
opt
:
t
<
T
>
)
->
T
{
pure
fn
get
<
copy
T
>
(
opt
:
t
<
T
>
)
->
T
{
alt
opt
{
some
(
x
)
{
ret
x
;
}
none
.
{
fail
"option none"
;
}
}
}
...
...
@@ -61,7 +61,7 @@ fn map<T, U>(opt: t<T>, f: block(T) -> U) -> t<U> {
Returns the contained value or a default
*/
fn
from_maybe
<
T
>
(
def
:
T
,
opt
:
t
<
T
>
)
->
T
{
pure
fn
from_maybe
<
T
>
(
def
:
T
,
opt
:
t
<
T
>
)
->
T
{
alt
opt
{
some
(
x
)
{
x
}
none
.
{
def
}
}
}
...
...
src/libcore/result.rs
浏览文件 @
dbfa1b56
...
...
@@ -42,7 +42,7 @@ fn get<T, U>(res: t<T, U>) -> T {
ok
(
t
)
{
t
}
err
(
_
)
{
// FIXME: Serialize the error value
// and include it in the fail message
// and include it in the fail message
(maybe just note it)
fail
"get called on error result"
;
}
}
...
...
@@ -71,7 +71,7 @@ fn get_err<T, U>(res: t<T, U>) -> U {
Returns true if the result is <ok>
*/
fn
success
<
T
,
U
>
(
res
:
t
<
T
,
U
>
)
->
bool
{
pure
fn
success
<
T
,
U
>
(
res
:
t
<
T
,
U
>
)
->
bool
{
alt
res
{
ok
(
_
)
{
true
}
err
(
_
)
{
false
}
...
...
@@ -83,10 +83,17 @@ fn success<T, U>(res: t<T, U>) -> bool {
Returns true if the result is <error>
*/
fn
failure
<
T
,
U
>
(
res
:
t
<
T
,
U
>
)
->
bool
{
pure
fn
failure
<
T
,
U
>
(
res
:
t
<
T
,
U
>
)
->
bool
{
!
success
(
res
)
}
pure
fn
to_either
<
copy
T
,
copy
U
>
(
res
:
t
<
U
,
T
>
)
->
either
::
t
<
T
,
U
>
{
alt
res
{
ok
(
res
)
{
either
::
right
(
res
)
}
err
(
fail_
)
{
either
::
left
(
fail_
)
}
}
}
/*
Function: chain
...
...
src/libcore/str.rs
浏览文件 @
dbfa1b56
...
...
@@ -26,14 +26,14 @@
Bytewise string equality
*/
fn
eq
(
&&
a
:
str
,
&&
b
:
str
)
->
bool
{
a
==
b
}
pure
fn
eq
(
&&
a
:
str
,
&&
b
:
str
)
->
bool
{
a
==
b
}
/*
Function: lteq
Bytewise less than or equal
*/
fn
lteq
(
&&
a
:
str
,
&&
b
:
str
)
->
bool
{
a
<=
b
}
pure
fn
lteq
(
&&
a
:
str
,
&&
b
:
str
)
->
bool
{
a
<=
b
}
/*
Function: hash
...
...
@@ -131,7 +131,7 @@ fn is_whitespace(s: str) -> bool {
Returns the length in bytes of a string
*/
fn
byte_len
(
s
:
str
)
->
uint
unsafe
{
pure
fn
byte_len
(
s
:
str
)
->
uint
unsafe
{
let
v
:
[
u8
]
=
unsafe
::
reinterpret_cast
(
s
);
let
vlen
=
vec
::
len
(
v
);
unsafe
::
leak
(
v
);
...
...
@@ -261,7 +261,7 @@ fn from_chars(chs: [char]) -> str {
FIXME: What does this function do?
*/
fn
utf8_char_width
(
b
:
u8
)
->
uint
{
pure
fn
utf8_char_width
(
b
:
u8
)
->
uint
{
let
byte
:
uint
=
b
as
uint
;
if
byte
<
128u
{
ret
1u
;
}
if
byte
<
192u
{
...
...
src/libcore/sys.rs
浏览文件 @
dbfa1b56
...
...
@@ -42,7 +42,7 @@ fn get_type_desc<T>() -> *type_desc {
Get a string representing the platform-dependent last error
*/
fn
last_os_error
()
->
str
{
r
et
rustrt
::
last_os_error
();
r
ustrt
::
last_os_error
()
}
/*
...
...
src/libcore/vec.rs
浏览文件 @
dbfa1b56
...
...
@@ -181,7 +181,7 @@ fn from_mut<copy T>(v: [mutable T]) -> [T] {
Predicates:
<is_not_empty> (v)
*/
fn
head
<
copy
T
>
(
v
:
[
const
T
])
:
is_not_empty
(
v
)
->
T
{
ret
v
[
0
];
}
pure
fn
head
<
copy
T
>
(
v
:
[
const
T
])
:
is_not_empty
(
v
)
->
T
{
ret
v
[
0
];
}
/*
Function: tail
...
...
@@ -221,7 +221,7 @@ fn init<copy T>(v: [const T]) -> [T] {
An option containing the last element of `v` if `v` is not empty, or
none if `v` is empty.
*/
fn
last
<
copy
T
>
(
v
:
[
const
T
])
->
option
::
t
<
T
>
{
pure
fn
last
<
copy
T
>
(
v
:
[
const
T
])
->
option
::
t
<
T
>
{
if
len
(
v
)
==
0u
{
ret
none
;
}
ret
some
(
v
[
len
(
v
)
-
1u
]);
}
...
...
@@ -234,7 +234,7 @@ fn last<copy T>(v: [const T]) -> option::t<T> {
Predicates:
<is_not_empty> (v)
*/
fn
last_total
<
copy
T
>
(
v
:
[
const
T
])
:
is_not_empty
(
v
)
->
T
{
pure
fn
last_total
<
copy
T
>
(
v
:
[
const
T
])
:
is_not_empty
(
v
)
->
T
{
ret
v
[
len
(
v
)
-
1u
];
}
...
...
src/libstd/bitv.rs
浏览文件 @
dbfa1b56
...
...
@@ -128,7 +128,7 @@ fn clone(v: t) -> t {
Retreive the value at index `i`
*/
fn
get
(
v
:
t
,
i
:
uint
)
->
bool
{
pure
fn
get
(
v
:
t
,
i
:
uint
)
->
bool
{
assert
(
i
<
v
.nbits
);
let
bits
=
uint_bits
;
let
w
=
i
/
bits
;
...
...
src/libstd/list.rs
浏览文件 @
dbfa1b56
...
...
@@ -112,7 +112,7 @@ fn len<copy T>(ls: list<T>) -> uint {
Returns all but the first element of a list
*/
fn
tail
<
copy
T
>
(
ls
:
list
<
T
>
)
->
list
<
T
>
{
pure
fn
tail
<
copy
T
>
(
ls
:
list
<
T
>
)
->
list
<
T
>
{
alt
ls
{
cons
(
_
,
tl
)
{
ret
*
tl
;
}
nil
.
{
fail
"list empty"
}
}
}
...
...
@@ -121,7 +121,7 @@ fn tail<copy T>(ls: list<T>) -> list<T> {
Returns the first element of a list
*/
fn
head
<
copy
T
>
(
ls
:
list
<
T
>
)
->
T
{
pure
fn
head
<
copy
T
>
(
ls
:
list
<
T
>
)
->
T
{
alt
ls
{
cons
(
hd
,
_
)
{
ret
hd
;
}
nil
.
{
fail
"list empty"
}
}
}
...
...
@@ -130,7 +130,7 @@ fn head<copy T>(ls: list<T>) -> T {
Appends one list to another
*/
fn
append
<
copy
T
>
(
l
:
list
<
T
>
,
m
:
list
<
T
>
)
->
list
<
T
>
{
pure
fn
append
<
copy
T
>
(
l
:
list
<
T
>
,
m
:
list
<
T
>
)
->
list
<
T
>
{
alt
l
{
nil
.
{
ret
m
;
}
cons
(
x
,
xs
)
{
let
rest
=
append
(
*
xs
,
m
);
ret
cons
(
x
,
@
rest
);
}
...
...
src/libstd/posix_fs.rs
浏览文件 @
dbfa1b56
...
...
@@ -30,6 +30,7 @@ fn list_dir(path: str) -> [str] {
}
// FIXME make pure when str::char_at is
fn
path_is_absolute
(
p
:
str
)
->
bool
{
ret
str
::
char_at
(
p
,
0u
)
==
'/'
;
}
const
path_sep
:
char
=
'/'
;
...
...
src/libstd/rope.rs
浏览文件 @
dbfa1b56
...
...
@@ -310,7 +310,7 @@ fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope {
A negative value if `left < right`, 0 if eq(left, right) or a positive
value if `left > right`
*/
*/
fn
cmp
(
left
:
rope
,
right
:
rope
)
->
int
{
alt
((
left
,
right
))
{
(
node
::
empty
.
,
node
::
empty
.
)
{
ret
0
;
}
...
...
src/libstd/unicode.rs
浏览文件 @
dbfa1b56
...
...
@@ -151,16 +151,16 @@ mod icu {
#[link_name
=
"icuuc"
]
#[abi
=
"cdecl"
]
native
mod
libicu
{
fn
u_hasBinaryProperty
(
c
:
UChar32
,
which
:
UProperty
)
->
UBool
;
pure
fn
u_hasBinaryProperty
(
c
:
UChar32
,
which
:
UProperty
)
->
UBool
;
}
}
fn
is_XID_start
(
c
:
char
)
->
bool
{
pure
fn
is_XID_start
(
c
:
char
)
->
bool
{
ret
icu
::
libicu
::
u_hasBinaryProperty
(
c
,
icu
::
UCHAR_XID_START
)
==
icu
::
TRUE
;
}
fn
is_XID_continue
(
c
:
char
)
->
bool
{
pure
fn
is_XID_continue
(
c
:
char
)
->
bool
{
ret
icu
::
libicu
::
u_hasBinaryProperty
(
c
,
icu
::
UCHAR_XID_START
)
==
icu
::
TRUE
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录