Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6e0611a4
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,发现更多精彩内容 >>
提交
6e0611a4
编写于
9月 30, 2014
作者:
N
Nick Cameron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Review and rebasing changes
上级
95cfc356
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
103 addition
and
42 deletion
+103
-42
src/libcollections/slice.rs
src/libcollections/slice.rs
+2
-1
src/libcollections/string.rs
src/libcollections/string.rs
+29
-0
src/libcollections/vec.rs
src/libcollections/vec.rs
+5
-10
src/libcore/slice.rs
src/libcore/slice.rs
+3
-5
src/libcore/str.rs
src/libcore/str.rs
+61
-23
src/libnative/io/pipe_windows.rs
src/libnative/io/pipe_windows.rs
+1
-1
src/libstd/os.rs
src/libstd/os.rs
+1
-1
src/libstd/rt/backtrace.rs
src/libstd/rt/backtrace.rs
+1
-1
未找到文件。
src/libcollections/slice.rs
浏览文件 @
6e0611a4
...
...
@@ -44,7 +44,8 @@
//!
//! A number of traits add methods that allow you to accomplish tasks with slices.
//! These traits include `ImmutableSlice`, which is defined for `&[T]` types,
//! and `MutableSlice`, defined for `&mut [T]` types.
//! `MutableSlice`, defined for `&mut [T]` types, and `Slice` and `SliceMut`
//! which are defined for `[T]`.
//!
//! An example is the `slice` method which enables slicing syntax `[a..b]` that
//! returns an immutable "view" into a `Vec` or another slice from the index
...
...
src/libcollections/string.rs
浏览文件 @
6e0611a4
...
...
@@ -927,6 +927,7 @@ fn add(&self, other: &S) -> String {
}
}
#[cfg(stage0)]
impl
ops
::
Slice
<
uint
,
str
>
for
String
{
#[inline]
fn
as_slice_
<
'a
>
(
&
'a
self
)
->
&
'a
str
{
...
...
@@ -949,6 +950,34 @@ fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str {
}
}
#[cfg(not(stage0))]
#[inline]
fn
str_to_slice
<
'a
,
U
:
Str
>
(
this
:
&
'a
U
)
->
&
'a
str
{
this
.as_slice
()
}
#[cfg(not(stage0))]
impl
ops
::
Slice
<
uint
,
str
>
for
String
{
#[inline]
fn
as_slice
<
'a
>
(
&
'a
self
)
->
&
'a
str
{
str_to_slice
(
self
)
}
#[inline]
fn
slice_from
<
'a
>
(
&
'a
self
,
from
:
&
uint
)
->
&
'a
str
{
self
[][
*
from
..
]
}
#[inline]
fn
slice_to
<
'a
>
(
&
'a
self
,
to
:
&
uint
)
->
&
'a
str
{
self
[][
..*
to
]
}
#[inline]
fn
slice
<
'a
>
(
&
'a
self
,
from
:
&
uint
,
to
:
&
uint
)
->
&
'a
str
{
self
[][
*
from
..*
to
]
}
}
/// Unsafe operations
#[unstable
=
"waiting on raw module conventions"
]
pub
mod
raw
{
...
...
src/libcollections/vec.rs
浏览文件 @
6e0611a4
...
...
@@ -462,6 +462,7 @@ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
// Annoying helper function because there are two Slice::as_slice functions in
// scope.
#[cfg(not(stage0))]
#[inline]
fn
slice_to_slice
<
'a
,
T
,
U
:
Slice
<
T
>>
(
this
:
&
'a
U
)
->
&
'a
[
T
]
{
this
.as_slice
()
...
...
@@ -983,7 +984,6 @@ pub fn sort_by(&mut self, compare: |&T, &T| -> Ordering) {
/// assert!(vec[0..2] == [1, 2]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice
<
'a
>
(
&
'a
self
,
start
:
uint
,
end
:
uint
)
->
&
'a
[
T
]
{
self
[
start
..
end
]
}
...
...
@@ -1019,7 +1019,7 @@ pub fn tail<'a>(&'a self) -> &'a [T] {
/// assert!(vec.tailn(2) == [3, 4]);
/// ```
#[inline]
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_from
"
]
pub
fn
tailn
<
'a
>
(
&
'a
self
,
n
:
uint
)
->
&
'a
[
T
]
{
self
[
n
..
]
}
...
...
@@ -1229,7 +1229,7 @@ pub fn push_all_move(&mut self, other: Vec<T>) {
}
/// Deprecated: use `slice_mut`.
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_from
"
]
pub
fn
mut_slice
<
'a
>
(
&
'a
mut
self
,
start
:
uint
,
end
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
start
..
end
]
...
...
@@ -1249,14 +1249,13 @@ pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
/// assert!(vec[mut 0..2] == [1, 2]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice_mut
<
'a
>
(
&
'a
mut
self
,
start
:
uint
,
end
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
start
..
end
]
}
/// Deprecated: use "slice_from_mut".
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_from_mut
"
]
pub
fn
mut_slice_from
<
'a
>
(
&
'a
mut
self
,
start
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
start
..
]
}
...
...
@@ -1274,13 +1273,12 @@ pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] {
/// assert!(vec[mut 2..] == [3, 4]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice_from_mut
<
'a
>
(
&
'a
mut
self
,
start
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
start
..
]
}
/// Deprecated: use `slice_to_mut`.
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_to_mut
"
]
pub
fn
mut_slice_to
<
'a
>
(
&
'a
mut
self
,
end
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
..
end
]
}
...
...
@@ -1298,7 +1296,6 @@ pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] {
/// assert!(vec[mut ..2] == [1, 2]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice_to_mut
<
'a
>
(
&
'a
mut
self
,
end
:
uint
)
->
&
'a
mut
[
T
]
{
self
[
mut
..
end
]
}
...
...
@@ -1375,7 +1372,6 @@ pub fn reverse(&mut self) {
/// assert!(vec[1..] == [2, 3]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice_from
<
'a
>
(
&
'a
self
,
start
:
uint
)
->
&
'a
[
T
]
{
self
[
start
..
]
}
...
...
@@ -1393,7 +1389,6 @@ pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
/// assert!(vec[..2] == [1, 2]);
/// ```
#[inline]
#[deprecated
=
"use slicing syntax"
]
pub
fn
slice_to
<
'a
>
(
&
'a
self
,
end
:
uint
)
->
&
'a
[
T
]
{
self
[
..
end
]
}
...
...
src/libcore/slice.rs
浏览文件 @
6e0611a4
...
...
@@ -152,7 +152,7 @@ pub trait ImmutableSlice<'a, T> {
fn
tail
(
&
self
)
->
&
'a
[
T
];
/// Returns all but the first `n' elements of a slice.
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_from
"
]
fn
tailn
(
&
self
,
n
:
uint
)
->
&
'a
[
T
];
/// Returns all but the last element of a slice.
...
...
@@ -161,7 +161,6 @@ pub trait ImmutableSlice<'a, T> {
/// Returns all but the last `n' elements of a slice.
#[deprecated
=
"use slice_to but note the arguments are different"
]
#[deprecated
=
"use slicing syntax, but note the arguments are different"
]
fn
initn
(
&
self
,
n
:
uint
)
->
&
'a
[
T
];
/// Returns the last element of a slice, or `None` if it is empty.
...
...
@@ -321,7 +320,7 @@ fn head(&self) -> Option<&'a T> {
fn
tail
(
&
self
)
->
&
'a
[
T
]
{
(
*
self
)[
1
..
]
}
#[inline]
#[deprecated
=
"use slic
ing syntax
"
]
#[deprecated
=
"use slic
e_from
"
]
fn
tailn
(
&
self
,
n
:
uint
)
->
&
'a
[
T
]
{
(
*
self
)[
n
..
]
}
#[inline]
...
...
@@ -330,7 +329,7 @@ fn init(&self) -> &'a [T] {
}
#[inline]
#[deprecated
=
"use slic
ing syntax
but note the arguments are different"
]
#[deprecated
=
"use slic
e_to
but note the arguments are different"
]
fn
initn
(
&
self
,
n
:
uint
)
->
&
'a
[
T
]
{
(
*
self
)[
..
self
.len
()
-
n
]
}
...
...
@@ -543,7 +542,6 @@ pub trait MutableSlice<'a, T> {
fn
get_mut
(
self
,
index
:
uint
)
->
Option
<&
'a
mut
T
>
;
/// Work with `self` as a mut slice.
/// Primarily intended for getting a &mut [T] from a [T, ..N].
#[deprecated
=
"use slicing syntax"
]
fn
as_mut_slice
(
self
)
->
&
'a
mut
[
T
];
/// Deprecated: use `iter_mut`.
...
...
src/libcore/str.rs
浏览文件 @
6e0611a4
...
...
@@ -1164,6 +1164,7 @@ impl<'a, S: Str> Equiv<S> for &'a str {
fn
equiv
(
&
self
,
other
:
&
S
)
->
bool
{
eq_slice
(
*
self
,
other
.as_slice
())
}
}
#[cfg(stage0)]
impl
ops
::
Slice
<
uint
,
str
>
for
str
{
#[inline]
fn
as_slice_
<
'a
>
(
&
'a
self
)
->
&
'a
str
{
...
...
@@ -1172,17 +1173,39 @@ fn as_slice_<'a>(&'a self) -> &'a str {
#[inline]
fn
slice_from_
<
'a
>
(
&
'a
self
,
from
:
&
uint
)
->
&
'a
str
{
s
elf
.slice_from
(
*
from
)
s
uper
::
slice_from_impl
(
&
self
,
*
from
)
}
#[inline]
fn
slice_to_
<
'a
>
(
&
'a
self
,
to
:
&
uint
)
->
&
'a
str
{
s
elf
.slice_to
(
*
to
)
s
uper
::
slice_to_impl
(
&
self
,
*
to
)
}
#[inline]
fn
slice_
<
'a
>
(
&
'a
self
,
from
:
&
uint
,
to
:
&
uint
)
->
&
'a
str
{
self
.slice
(
*
from
,
*
to
)
super
::
slice_impl
(
&
self
,
*
from
,
*
to
)
}
}
#[cfg(not(stage0))]
impl
ops
::
Slice
<
uint
,
str
>
for
str
{
#[inline]
fn
as_slice
<
'a
>
(
&
'a
self
)
->
&
'a
str
{
self
}
#[inline]
fn
slice_from
<
'a
>
(
&
'a
self
,
from
:
&
uint
)
->
&
'a
str
{
super
::
slice_from_impl
(
&
self
,
*
from
)
}
#[inline]
fn
slice_to
<
'a
>
(
&
'a
self
,
to
:
&
uint
)
->
&
'a
str
{
super
::
slice_to_impl
(
&
self
,
*
to
)
}
#[inline]
fn
slice
<
'a
>
(
&
'a
self
,
from
:
&
uint
,
to
:
&
uint
)
->
&
'a
str
{
super
::
slice_impl
(
&
self
,
*
from
,
*
to
)
}
}
}
...
...
@@ -1835,6 +1858,38 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! {
begin
,
end
,
s
);
}
#[inline]
fn
slice_impl
<
'a
>
(
this
:
&&
'a
str
,
begin
:
uint
,
end
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
begin
<=
end
&&
this
.is_char_boundary
(
begin
)
&&
this
.is_char_boundary
(
end
)
{
unsafe
{
raw
::
slice_unchecked
(
*
this
,
begin
,
end
)
}
}
else
{
slice_error_fail
(
*
this
,
begin
,
end
)
}
}
#[inline]
fn
slice_from_impl
<
'a
>
(
this
:
&&
'a
str
,
begin
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
this
.is_char_boundary
(
begin
)
{
unsafe
{
raw
::
slice_unchecked
(
*
this
,
begin
,
this
.len
())
}
}
else
{
slice_error_fail
(
*
this
,
begin
,
this
.len
())
}
}
#[inline]
fn
slice_to_impl
<
'a
>
(
this
:
&&
'a
str
,
end
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
this
.is_char_boundary
(
end
)
{
unsafe
{
raw
::
slice_unchecked
(
*
this
,
0
,
end
)
}
}
else
{
slice_error_fail
(
*
this
,
0
,
end
)
}
}
impl
<
'a
>
StrSlice
<
'a
>
for
&
'a
str
{
#[inline]
fn
contains
<
'a
>
(
&
self
,
needle
:
&
'a
str
)
->
bool
{
...
...
@@ -1938,34 +1993,17 @@ fn char_len(&self) -> uint { self.chars().count() }
#[inline]
fn
slice
(
&
self
,
begin
:
uint
,
end
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
begin
<=
end
&&
self
.is_char_boundary
(
begin
)
&&
self
.is_char_boundary
(
end
)
{
unsafe
{
raw
::
slice_unchecked
(
*
self
,
begin
,
end
)
}
}
else
{
slice_error_fail
(
*
self
,
begin
,
end
)
}
slice_impl
(
self
,
begin
,
end
)
}
#[inline]
fn
slice_from
(
&
self
,
begin
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
self
.is_char_boundary
(
begin
)
{
unsafe
{
raw
::
slice_unchecked
(
*
self
,
begin
,
self
.len
())
}
}
else
{
slice_error_fail
(
*
self
,
begin
,
self
.len
())
}
slice_from_impl
(
self
,
begin
)
}
#[inline]
fn
slice_to
(
&
self
,
end
:
uint
)
->
&
'a
str
{
// is_char_boundary checks that the index is in [0, .len()]
if
self
.is_char_boundary
(
end
)
{
unsafe
{
raw
::
slice_unchecked
(
*
self
,
0
,
end
)
}
}
else
{
slice_error_fail
(
*
self
,
0
,
end
)
}
slice_to_impl
(
self
,
end
)
}
fn
slice_chars
(
&
self
,
begin
:
uint
,
end
:
uint
)
->
&
'a
str
{
...
...
src/libnative/io/pipe_windows.rs
浏览文件 @
6e0611a4
...
...
@@ -448,7 +448,7 @@ fn write(&mut self, buf: &[u8]) -> IoResult<()> {
}
let
ret
=
unsafe
{
libc
::
WriteFile
(
self
.handle
(),
buf
.slice_from
(
offset
)
.as_ptr
()
as
libc
::
LPVOID
,
buf
[
offset
..
]
.as_ptr
()
as
libc
::
LPVOID
,
(
buf
.len
()
-
offset
)
as
libc
::
DWORD
,
&
mut
bytes_written
,
&
mut
overlapped
)
...
...
src/libstd/os.rs
浏览文件 @
6e0611a4
...
...
@@ -144,7 +144,7 @@ pub mod windows {
use
option
::{
None
,
Option
};
use
option
;
use
os
::
TMPBUF_SZ
;
use
slice
::
{
MutableSlice
,
ImmutableSlice
}
;
use
slice
::
MutableSlice
;
use
string
::
String
;
use
str
::
StrSlice
;
use
vec
::
Vec
;
...
...
src/libstd/rt/backtrace.rs
浏览文件 @
6e0611a4
...
...
@@ -999,7 +999,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
let
bytes
=
cstr
.as_bytes
();
match
cstr
.as_str
()
{
Some
(
s
)
=>
try!
(
super
::
demangle
(
w
,
s
)),
None
=>
try!
(
w
.write
(
bytes
.slice_to
(
bytes
.len
()
-
1
)
)),
None
=>
try!
(
w
.write
(
bytes
[
..
bytes
.len
()
-
1
]
)),
}
}
try!
(
w
.write
([
'\n'
as
u8
]));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录