Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
78d4bf85
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,发现更多精彩内容 >>
提交
78d4bf85
编写于
2月 21, 2014
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #12253 : pcwalton/rust/more-vec-ng, r=alexcrichton
r? @brson
上级
b5995b4e
03b79109
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
221 addition
and
9 deletion
+221
-9
src/libserialize/serialize.rs
src/libserialize/serialize.rs
+21
-0
src/libstd/macros.rs
src/libstd/macros.rs
+10
-0
src/libstd/str.rs
src/libstd/str.rs
+13
-0
src/libstd/to_bytes.rs
src/libstd/to_bytes.rs
+8
-0
src/libstd/vec_ng.rs
src/libstd/vec_ng.rs
+169
-9
未找到文件。
src/libserialize/serialize.rs
浏览文件 @
78d4bf85
...
...
@@ -18,6 +18,7 @@
use
std
::
rc
::
Rc
;
use
std
::
trie
::{
TrieMap
,
TrieSet
};
use
std
::
vec
;
use
std
::
vec_ng
::
Vec
;
pub
trait
Encoder
{
// Primitive types:
...
...
@@ -435,6 +436,26 @@ fn decode(d: &mut D) -> ~[T] {
}
}
impl
<
S
:
Encoder
,
T
:
Encodable
<
S
>>
Encodable
<
S
>
for
Vec
<
T
>
{
fn
encode
(
&
self
,
s
:
&
mut
S
)
{
s
.emit_seq
(
self
.len
(),
|
s
|
{
for
(
i
,
e
)
in
self
.iter
()
.enumerate
()
{
s
.emit_seq_elt
(
i
,
|
s
|
e
.encode
(
s
))
}
})
}
}
impl
<
D
:
Decoder
,
T
:
Decodable
<
D
>>
Decodable
<
D
>
for
Vec
<
T
>
{
fn
decode
(
d
:
&
mut
D
)
->
Vec
<
T
>
{
d
.read_seq
(|
d
,
len
|
{
Vec
::
from_fn
(
len
,
|
i
|
{
d
.read_seq_elt
(
i
,
|
d
|
Decodable
::
decode
(
d
))
})
})
}
}
impl
<
S
:
Encoder
,
T
:
Encodable
<
S
>>
Encodable
<
S
>
for
Option
<
T
>
{
fn
encode
(
&
self
,
s
:
&
mut
S
)
{
s
.emit_option
(|
s
|
{
...
...
src/libstd/macros.rs
浏览文件 @
78d4bf85
...
...
@@ -358,3 +358,13 @@ fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
macro_rules!
try
(
(
$e:expr
)
=>
(
match
$e
{
Ok
(
e
)
=>
e
,
Err
(
e
)
=>
return
Err
(
e
)
})
)
#[macro_export]
macro_rules!
vec
(
(
$
(
$e:expr
),
*
)
=>
({
let
mut
temp
=
::
std
::
vec_ng
::
Vec
::
new
();
$
(
temp
.push
(
$e
);)
*
temp
})
)
src/libstd/str.rs
浏览文件 @
78d4bf85
...
...
@@ -101,6 +101,7 @@ fn main() {
use
from_str
::
FromStr
;
use
vec
;
use
vec
::{
OwnedVector
,
OwnedCloneableVector
,
ImmutableVector
,
MutableVector
};
use
vec_ng
::
Vec
;
use
default
::
Default
;
use
to_bytes
::{
IterBytes
,
Cb
};
use
unstable
::
raw
::
Repr
;
...
...
@@ -222,6 +223,18 @@ fn connect(&self, sep: &str) -> ~str {
}
}
impl
<
'a
,
S
:
Str
>
StrVector
for
Vec
<
S
>
{
#[inline]
fn
concat
(
&
self
)
->
~
str
{
self
.as_slice
()
.concat
()
}
#[inline]
fn
connect
(
&
self
,
sep
:
&
str
)
->
~
str
{
self
.as_slice
()
.connect
(
sep
)
}
}
/// Something that can be used to compare against a character
pub
trait
CharEq
{
/// Determine if the splitter should split at the given character
...
...
src/libstd/to_bytes.rs
浏览文件 @
78d4bf85
...
...
@@ -21,6 +21,7 @@
use
rc
::
Rc
;
use
str
::{
Str
,
StrSlice
};
use
vec
::{
Vector
,
ImmutableVector
};
use
vec_ng
::
Vec
;
pub
type
Cb
<
'a
>
=
'a
|
buf
:
&
[
u8
]|
->
bool
;
...
...
@@ -266,6 +267,13 @@ fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
}
}
impl
<
A
:
IterBytes
>
IterBytes
for
Vec
<
A
>
{
#[inline]
fn
iter_bytes
(
&
self
,
lsb0
:
bool
,
f
:
Cb
)
->
bool
{
self
.as_slice
()
.iter_bytes
(
lsb0
,
f
)
}
}
impl
<
'a
>
IterBytes
for
&
'a
str
{
#[inline]
fn
iter_bytes
(
&
self
,
_
lsb0
:
bool
,
f
:
Cb
)
->
bool
{
...
...
src/libstd/vec_ng.rs
浏览文件 @
78d4bf85
...
...
@@ -11,20 +11,21 @@
// Migrate documentation over from `std::vec` when it is removed.
#[doc(hidden)]
;
use
ops
::
Drop
;
use
option
::{
None
,
Option
,
Some
};
use
cast
::{
forget
,
transmute
};
use
clone
::
Clone
;
use
iter
::{
DoubleEndedIterator
,
Iterator
};
use
num
::
CheckedMul
;
use
cmp
::{
Eq
,
Ordering
,
TotalEq
,
TotalOrd
};
use
container
::
Container
;
use
iter
::{
DoubleEndedIterator
,
FromIterator
,
Iterator
};
use
libc
::{
free
,
c_void
};
use
mem
::{
size_of
,
move_val_init
};
use
cast
::{
forget
,
transmute
};
use
num
::
CheckedMul
;
use
ops
::
Drop
;
use
option
::{
None
,
Option
,
Some
};
use
ptr
::
RawPtr
;
use
ptr
;
use
rt
::
global_heap
::{
malloc_raw
,
realloc_raw
};
use
vec
::{
ImmutableVector
,
Items
,
MutableVector
};
use
unstable
::
raw
::
Slice
;
use
ptr
;
use
ptr
::
RawPtr
;
use
libc
::{
free
,
c_void
};
use
vec
::{
ImmutableVector
,
Items
,
MutItems
,
MutableVector
,
RevItems
};
pub
struct
Vec
<
T
>
{
priv
len
:
uint
,
...
...
@@ -71,6 +72,55 @@ pub fn from_elem(length: uint, value: T) -> Vec<T> {
xs
}
}
#[inline]
pub
fn
push_all
(
&
mut
self
,
other
:
&
[
T
])
{
for
element
in
other
.iter
()
{
self
.push
((
*
element
)
.clone
())
}
}
}
impl
<
T
:
Clone
>
Clone
for
Vec
<
T
>
{
fn
clone
(
&
self
)
->
Vec
<
T
>
{
let
mut
vector
=
Vec
::
with_capacity
(
self
.len
());
for
element
in
self
.iter
()
{
vector
.push
((
*
element
)
.clone
())
}
vector
}
}
impl
<
T
>
FromIterator
<
T
>
for
Vec
<
T
>
{
fn
from_iterator
<
I
:
Iterator
<
T
>>
(
iterator
:
&
mut
I
)
->
Vec
<
T
>
{
let
(
lower
,
_
)
=
iterator
.size_hint
();
let
mut
vector
=
Vec
::
with_capacity
(
lower
);
for
element
in
*
iterator
{
vector
.push
(
element
)
}
vector
}
}
impl
<
T
:
Eq
>
Eq
for
Vec
<
T
>
{
#[inline]
fn
eq
(
&
self
,
other
:
&
Vec
<
T
>
)
->
bool
{
self
.as_slice
()
==
other
.as_slice
()
}
}
impl
<
T
:
TotalEq
>
TotalEq
for
Vec
<
T
>
{
#[inline]
fn
equals
(
&
self
,
other
:
&
Vec
<
T
>
)
->
bool
{
self
.as_slice
()
.equals
(
&
other
.as_slice
())
}
}
impl
<
T
:
TotalOrd
>
TotalOrd
for
Vec
<
T
>
{
#[inline]
fn
cmp
(
&
self
,
other
:
&
Vec
<
T
>
)
->
Ordering
{
self
.as_slice
()
.cmp
(
&
other
.as_slice
())
}
}
impl
<
T
>
Container
for
Vec
<
T
>
{
...
...
@@ -180,8 +230,117 @@ pub fn move_iter(self) -> MoveItems<T> {
pub
unsafe
fn
set_len
(
&
mut
self
,
len
:
uint
)
{
self
.len
=
len
;
}
#[inline]
pub
fn
get
<
'a
>
(
&
'a
self
,
index
:
uint
)
->
&
'a
T
{
&
self
.as_slice
()[
index
]
}
#[inline]
pub
fn
get_mut
<
'a
>
(
&
'a
mut
self
,
index
:
uint
)
->
&
'a
mut
T
{
&
mut
self
.as_mut_slice
()[
index
]
}
#[inline]
pub
fn
iter
<
'a
>
(
&
'a
self
)
->
Items
<
'a
,
T
>
{
self
.as_slice
()
.iter
()
}
#[inline]
pub
fn
mut_iter
<
'a
>
(
&
'a
mut
self
)
->
MutItems
<
'a
,
T
>
{
self
.as_mut_slice
()
.mut_iter
()
}
#[inline]
pub
fn
sort_by
(
&
mut
self
,
compare
:
|
&
T
,
&
T
|
->
Ordering
)
{
self
.as_mut_slice
()
.sort_by
(
compare
)
}
#[inline]
pub
fn
slice
<
'a
>
(
&
'a
self
,
start
:
uint
,
end
:
uint
)
->
&
'a
[
T
]
{
self
.as_slice
()
.slice
(
start
,
end
)
}
#[inline]
pub
fn
tail
<
'a
>
(
&
'a
self
)
->
&
'a
[
T
]
{
self
.as_slice
()
.tail
()
}
#[inline]
pub
fn
last
<
'a
>
(
&
'a
self
)
->
Option
<&
'a
T
>
{
self
.as_slice
()
.last
()
}
#[inline]
pub
fn
mut_last
<
'a
>
(
&
'a
mut
self
)
->
Option
<&
'a
mut
T
>
{
self
.as_mut_slice
()
.mut_last
()
}
#[inline]
pub
fn
swap_remove
(
&
mut
self
,
index
:
uint
)
->
T
{
let
length
=
self
.len
();
if
index
>=
length
{
fail
!
(
"Vec::swap_remove - index {} >= length {}"
,
index
,
length
);
}
if
index
<
length
-
1
{
self
.as_mut_slice
()
.swap
(
index
,
length
-
1
);
}
self
.pop
()
.unwrap
()
}
#[inline]
pub
fn
unshift
(
&
mut
self
,
element
:
T
)
{
self
.insert
(
0
,
element
)
}
pub
fn
insert
(
&
mut
self
,
index
:
uint
,
element
:
T
)
{
let
len
=
self
.len
();
assert
!
(
index
<=
len
);
// space for the new element
self
.reserve_exact
(
len
+
1
);
unsafe
{
// infallible
// The spot to put the new value
{
let
slice
=
self
.as_mut_slice
();
let
p
=
slice
.as_mut_ptr
()
.offset
(
index
as
int
);
// Shift everything over to make space. (Duplicating the
// `index`th element into two consecutive places.)
ptr
::
copy_memory
(
p
.offset
(
1
),
&*
p
,
len
-
index
);
// Write it in, overwriting the first copy of the `index`th
// element.
move_val_init
(
&
mut
*
p
,
element
);
}
self
.set_len
(
len
+
1
);
}
}
#[inline]
pub
fn
rev_iter
<
'a
>
(
&
'a
self
)
->
RevItems
<
'a
,
T
>
{
self
.as_slice
()
.rev_iter
()
}
#[inline]
pub
fn
map
<
U
>
(
&
self
,
f
:
|
t
:
&
T
|
->
U
)
->
Vec
<
U
>
{
self
.iter
()
.map
(
f
)
.collect
()
}
pub
fn
push_all_move
(
&
mut
self
,
other
:
Vec
<
T
>
)
{
for
element
in
other
.move_iter
()
{
self
.push
(
element
)
}
}
pub
fn
slice_from
<
'a
>
(
&
'a
self
,
start
:
uint
)
->
&
'a
[
T
]
{
self
.as_slice
()
.slice_from
(
start
)
}
}
#[inline]
pub
fn
append
<
T
:
Clone
>
(
mut
first
:
Vec
<
T
>
,
second
:
&
[
T
])
->
Vec
<
T
>
{
first
.push_all
(
second
);
first
}
#[unsafe_destructor]
impl
<
T
>
Drop
for
Vec
<
T
>
{
...
...
@@ -233,3 +392,4 @@ fn drop(&mut self) {
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录