Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fdf0c1b3
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,发现更多精彩内容 >>
提交
fdf0c1b3
编写于
7月 11, 2012
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: Newtype a bunch of types in libcore
上级
c0961bb8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
141 addition
and
21 deletion
+141
-21
src/libcore/dvec.rs
src/libcore/dvec.rs
+9
-5
src/libcore/iter-trait.rs
src/libcore/iter-trait.rs
+1
-1
src/libcore/iter.rs
src/libcore/iter.rs
+9
-0
src/libcore/pipes.rs
src/libcore/pipes.rs
+22
-5
src/libcore/ptr.rs
src/libcore/ptr.rs
+6
-1
src/libcore/str.rs
src/libcore/str.rs
+36
-2
src/libcore/vec.rs
src/libcore/vec.rs
+58
-7
未找到文件。
src/libcore/dvec.rs
浏览文件 @
fdf0c1b3
...
...
@@ -46,28 +46,32 @@
* pointers achieved about 103 million pushes/second. Using an option
* type could only produce 47 million pushes/second.
*/
type
dvec
<
A
>
=
{
type
dvec
_
<
A
>
=
{
mut
data
:
~
[
mut
A
]
};
enum
dvec
<
A
>
{
dvec_
(
dvec_
<
A
>
)
}
/// Creates a new, empty dvec
fn
dvec
<
A
>
()
->
dvec
<
A
>
{
{
mut
data
:
~
[
mut
]}
dvec_
({
mut
data
:
~
[
mut
]})
}
/// Creates a new dvec with a single element
fn
from_elem
<
A
>
(
+
e
:
A
)
->
dvec
<
A
>
{
{
mut
data
:
~
[
mut
e
]}
dvec_
({
mut
data
:
~
[
mut
e
]})
}
/// Creates a new dvec with the contents of a vector
fn
from_vec
<
A
>
(
+
v
:
~
[
mut
A
])
->
dvec
<
A
>
{
{
mut
data
:
v
}
dvec_
({
mut
data
:
v
})
}
/// Consumes the vector and returns its contents
fn
unwrap
<
A
>
(
-
d
:
dvec
<
A
>
)
->
~
[
mut
A
]
{
let
{
data
:
v
}
<-
d
;
let
dvec_
({
data
:
v
})
<-
d
;
ret
v
;
}
...
...
src/libcore/iter-trait.rs
浏览文件 @
fdf0c1b3
...
...
@@ -21,7 +21,7 @@ fn position(f: fn(A) -> bool) -> option<uint> {
}
}
impl
extensions
<
A
:
copy
>
for
IMPL_T
<
A
>
{
impl
extensions
<
A
:
copy
>
of
iter
::
copyable_iter
<
A
>
for
IMPL_T
<
A
>
{
fn
filter_to_vec
(
pred
:
fn
(
A
)
->
bool
)
->
~
[
A
]
{
iter
::
filter_to_vec
(
self
,
pred
)
}
...
...
src/libcore/iter.rs
浏览文件 @
fdf0c1b3
...
...
@@ -7,6 +7,15 @@
fn
times
(
it
:
fn
()
->
bool
);
}
trait
copyable_iter
<
A
:
copy
>
{
fn
filter_to_vec
(
pred
:
fn
(
A
)
->
bool
)
->
~
[
A
];
fn
map_to_vec
<
B
>
(
op
:
fn
(
A
)
->
B
)
->
~
[
B
];
fn
to_vec
()
->
~
[
A
];
fn
min
()
->
A
;
fn
max
()
->
A
;
fn
find
(
p
:
fn
(
A
)
->
bool
)
->
option
<
A
>
;
}
fn
eachi
<
A
,
IA
:
base_iter
<
A
>>
(
self
:
IA
,
blk
:
fn
(
uint
,
A
)
->
bool
)
{
let
mut
i
=
0u
;
for
self
.each
|
a
|
{
...
...
src/libcore/pipes.rs
浏览文件 @
fdf0c1b3
...
...
@@ -11,16 +11,24 @@ enum state {
terminated
}
type
packet_header
=
{
type
packet_header
_
=
{
mut
state
:
state
,
mut
blocked_task
:
option
<*
rust_task
>
,
};
type
packet
<
T
:
send
>
=
{
enum
packet_header
{
packet_header_
(
packet_header_
)
}
type
packet_
<
T
:
send
>
=
{
header
:
packet_header
,
mut
payload
:
option
<
T
>
};
enum
packet
<
T
:
send
>
{
packet_
(
packet_
<
T
>
)
}
fn
packet
<
T
:
send
>
()
->
*
packet
<
T
>
unsafe
{
let
p
:
*
packet
<
T
>
=
unsafe
::
transmute
(
~
{
header
:
{
...
...
@@ -428,8 +436,17 @@ fn spawn_service_recv<T: send>(
}
}
type
chan
<
T
:
send
>
=
{
mut
endp
:
option
<
streamp
::
client
::
open
<
T
>>
};
type
port
<
T
:
send
>
=
{
mut
endp
:
option
<
streamp
::
server
::
open
<
T
>>
};
type
chan_
<
T
:
send
>
=
{
mut
endp
:
option
<
streamp
::
client
::
open
<
T
>>
};
enum
chan
<
T
:
send
>
{
chan_
(
chan_
<
T
>
)
}
type
port_
<
T
:
send
>
=
{
mut
endp
:
option
<
streamp
::
server
::
open
<
T
>>
};
enum
port
<
T
:
send
>
{
port_
(
port_
<
T
>
)
}
fn
stream
<
T
:
send
>
()
->
(
chan
<
T
>
,
port
<
T
>
)
{
let
(
c
,
s
)
=
streamp
::
init
();
...
...
@@ -439,7 +456,7 @@ fn stream<T:send>() -> (chan<T>, port<T>) {
unsafe
{
let
y
<-
*
ptr
::
addr_of
(
x
);
y
}]
];
(
{
mut
endp
:
some
(
c
)
},
{
mut
endp
:
some
(
s
)
}
)
(
chan_
({
mut
endp
:
some
(
c
)
}),
port_
({
mut
endp
:
some
(
s
)
})
)
}
impl
chan
<
T
:
send
>
for
chan
<
T
>
{
...
...
src/libcore/ptr.rs
浏览文件 @
fdf0c1b3
...
...
@@ -123,8 +123,13 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
libc_
::
memset
(
dst
as
*
c_void
,
c
as
libc
::
c_int
,
n
as
size_t
);
}
trait
ptr
{
pure
fn
is_null
()
->
bool
;
pure
fn
is_not_null
()
->
bool
;
}
/// Extension methods for pointers
impl
extensions
<
T
>
for
*
T
{
impl
extensions
<
T
>
of
ptr
for
*
T
{
/// Returns true if the pointer is equal to the null pointer.
pure
fn
is_null
()
->
bool
{
is_null
(
self
)
}
...
...
src/libcore/str.rs
浏览文件 @
fdf0c1b3
...
...
@@ -1882,8 +1882,15 @@ fn test_from_buf_len() {
}
trait
unique_str
{
fn
trim
()
->
self
;
fn
trim_left
()
->
self
;
fn
trim_right
()
->
self
;
pure
fn
+
(
rhs
:
str
/&
)
->
self
;
}
/// Extension methods for strings
impl
extensions
for
str
{
impl
extensions
of
unique_str
for
str
{
/// Returns a string with leading and trailing whitespace removed
#[inline]
fn
trim
()
->
str
{
trim
(
self
)
}
...
...
@@ -1901,8 +1908,35 @@ fn trim_right() -> str { trim_right(self) }
}
}
trait
str_slice
{
fn
all
(
it
:
fn
(
char
)
->
bool
)
->
bool
;
fn
any
(
it
:
fn
(
char
)
->
bool
)
->
bool
;
fn
contains
(
needle
:
str
/&
a
)
->
bool
;
fn
contains_char
(
needle
:
char
)
->
bool
;
fn
each
(
it
:
fn
(
u8
)
->
bool
);
fn
eachi
(
it
:
fn
(
uint
,
u8
)
->
bool
);
fn
each_char
(
it
:
fn
(
char
)
->
bool
);
fn
each_chari
(
it
:
fn
(
uint
,
char
)
->
bool
);
fn
ends_with
(
needle
:
str
/&
)
->
bool
;
fn
is_empty
()
->
bool
;
fn
is_not_empty
()
->
bool
;
fn
is_whitespace
()
->
bool
;
fn
is_alphanumeric
()
->
bool
;
pure
fn
len
()
->
uint
;
fn
slice
(
begin
:
uint
,
end
:
uint
)
->
str
;
fn
split
(
sepfn
:
fn
(
char
)
->
bool
)
->
~
[
str
];
fn
split_char
(
sep
:
char
)
->
~
[
str
];
fn
split_str
(
sep
:
str
/&
a
)
->
~
[
str
];
fn
starts_with
(
needle
:
str
/&
a
)
->
bool
;
fn
substr
(
begin
:
uint
,
n
:
uint
)
->
str
;
fn
to_lower
()
->
str
;
fn
to_upper
()
->
str
;
fn
escape_default
()
->
str
;
fn
escape_unicode
()
->
str
;
}
/// Extension methods for strings
impl
extensions
/&
for
str
/&
{
impl
extensions
/&
of
str_slice
for
str
/&
{
/**
* Return true if a predicate matches all characters or if the string
* contains no characters
...
...
src/libcore/vec.rs
浏览文件 @
fdf0c1b3
...
...
@@ -1181,22 +1181,32 @@ fn as_mut_buf<E,T>(v: &[mut E], f: fn(*mut E) -> T) -> T {
}
}
impl
extensions
<
T
:
copy
>
for
~
[
T
]
{
trait
vec_concat
<
T
>
{
pure
fn
+
(
rhs
:
&
[
const
T
])
->
self
;
}
impl
extensions
<
T
:
copy
>
of
vec_concat
<
T
>
for
~
[
T
]
{
#[inline(always)]
pure
fn
+
(
rhs
:
&
[
const
T
])
->
~
[
T
]
{
append
(
self
,
rhs
)
}
}
impl
extensions
<
T
:
copy
>
for
~
[
mut
T
]
{
impl
extensions
<
T
:
copy
>
of
vec_concat
<
T
>
for
~
[
mut
T
]
{
#[inline(always)]
pure
fn
+
(
rhs
:
&
[
const
T
])
->
~
[
mut
T
]
{
append_mut
(
self
,
rhs
)
}
}
trait
const_vector
{
pure
fn
is_empty
()
->
bool
;
pure
fn
is_not_empty
()
->
bool
;
pure
fn
len
()
->
uint
;
}
/// Extension methods for vectors
impl
extensions
/&<
T
>
for
&
[
const
T
]
{
impl
extensions
/&<
T
>
of
const_vector
for
&
[
const
T
]
{
/// Returns true if a vector contains no elements
#[inline]
pure
fn
is_empty
()
->
bool
{
is_empty
(
self
)
}
...
...
@@ -1208,8 +1218,16 @@ impl extensions/&<T> for &[const T] {
pure
fn
len
()
->
uint
{
len
(
self
)
}
}
trait
copyable_vector
<
T
>
{
pure
fn
head
()
->
T
;
pure
fn
init
()
->
~
[
T
];
pure
fn
last
()
->
T
;
pure
fn
slice
(
start
:
uint
,
end
:
uint
)
->
~
[
T
];
pure
fn
tail
()
->
~
[
T
];
}
/// Extension methods for vectors
impl
extensions
/&<
T
:
copy
>
for
&
[
const
T
]
{
impl
extensions
/&<
T
:
copy
>
of
copyable_vector
<
T
>
for
&
[
const
T
]
{
/// Returns the first element of a vector
#[inline]
pure
fn
head
()
->
T
{
head
(
self
)
}
...
...
@@ -1227,8 +1245,26 @@ impl extensions/&<T: copy> for &[const T] {
pure
fn
tail
()
->
~
[
T
]
{
tail
(
self
)
}
}
trait
immutable_vector
/&<
T
>
{
pure
fn
foldr
<
U
:
copy
>
(
z
:
U
,
p
:
fn
(
T
,
U
)
->
U
)
->
U
;
pure
fn
iter
(
f
:
fn
(
T
));
pure
fn
iteri
(
f
:
fn
(
uint
,
T
));
pure
fn
position
(
f
:
fn
(
T
)
->
bool
)
->
option
<
uint
>
;
pure
fn
position_elem
(
x
:
T
)
->
option
<
uint
>
;
pure
fn
riter
(
f
:
fn
(
T
));
pure
fn
riteri
(
f
:
fn
(
uint
,
T
));
pure
fn
rposition
(
f
:
fn
(
T
)
->
bool
)
->
option
<
uint
>
;
pure
fn
rposition_elem
(
x
:
T
)
->
option
<
uint
>
;
pure
fn
map
<
U
>
(
f
:
fn
(
T
)
->
U
)
->
~
[
U
];
pure
fn
mapi
<
U
>
(
f
:
fn
(
uint
,
T
)
->
U
)
->
~
[
U
];
fn
map_r
<
U
>
(
f
:
fn
(
x
:
&
self
.T
)
->
U
)
->
~
[
U
];
pure
fn
alli
(
f
:
fn
(
uint
,
T
)
->
bool
)
->
bool
;
pure
fn
flat_map
<
U
>
(
f
:
fn
(
T
)
->
~
[
U
])
->
~
[
U
];
pure
fn
filter_map
<
U
:
copy
>
(
f
:
fn
(
T
)
->
option
<
U
>
)
->
~
[
U
];
}
/// Extension methods for vectors
impl
extensions
/&<
T
>
for
&
[
T
]
{
impl
extensions
/&<
T
>
of
immutable_vector
<
T
>
for
&
[
T
]
{
/// Reduce a vector from right to left
#[inline]
pure
fn
foldr
<
U
:
copy
>
(
z
:
U
,
p
:
fn
(
T
,
U
)
->
U
)
->
U
{
foldr
(
self
,
z
,
p
)
}
...
...
@@ -1336,8 +1372,14 @@ fn map_r<U>(f: fn(x: &self.T) -> U) -> ~[U] {
}
}
trait
immutable_copyable_vector
<
T
>
{
pure
fn
filter
(
f
:
fn
(
T
)
->
bool
)
->
~
[
T
];
pure
fn
find
(
f
:
fn
(
T
)
->
bool
)
->
option
<
T
>
;
pure
fn
rfind
(
f
:
fn
(
T
)
->
bool
)
->
option
<
T
>
;
}
/// Extension methods for vectors
impl
extensions
/&<
T
:
copy
>
for
&
[
T
]
{
impl
extensions
/&<
T
:
copy
>
of
immutable_copyable_vector
<
T
>
for
&
[
T
]
{
/**
* Construct a new vector from the elements of a vector for which some
* predicate holds.
...
...
@@ -1510,7 +1552,16 @@ fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
fn
contains
(
x
:
A
)
->
bool
{
iter
::
contains
(
self
,
x
)
}
fn
count
(
x
:
A
)
->
uint
{
iter
::
count
(
self
,
x
)
}
}
impl
extensions
/&<
A
:
copy
>
for
&
[
const
A
]
{
trait
iter_trait_extensions
<
A
>
{
fn
filter_to_vec
(
pred
:
fn
(
A
)
->
bool
)
->
~
[
A
];
fn
map_to_vec
<
B
>
(
op
:
fn
(
A
)
->
B
)
->
~
[
B
];
fn
to_vec
()
->
~
[
A
];
fn
min
()
->
A
;
fn
max
()
->
A
;
}
impl
extensions
/&<
A
:
copy
>
of
iter_trait_extensions
<
A
>
for
&
[
const
A
]
{
fn
filter_to_vec
(
pred
:
fn
(
A
)
->
bool
)
->
~
[
A
]
{
iter
::
filter_to_vec
(
self
,
pred
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录