Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c66c6e96
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,发现更多精彩内容 >>
提交
c66c6e96
编写于
4月 11, 2017
作者:
C
Clar Charr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More methods for str boxes.
上级
968ae7ba
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
60 addition
and
8 deletion
+60
-8
src/doc/unstable-book/src/SUMMARY.md
src/doc/unstable-book/src/SUMMARY.md
+1
-0
src/doc/unstable-book/src/library-features/str-box-extras.md
src/doc/unstable-book/src/library-features/str-box-extras.md
+9
-0
src/liballoc/boxed.rs
src/liballoc/boxed.rs
+13
-5
src/liballoc/lib.rs
src/liballoc/lib.rs
+2
-0
src/liballoc/str.rs
src/liballoc/str.rs
+21
-0
src/libcollections/lib.rs
src/libcollections/lib.rs
+1
-0
src/libcollections/str.rs
src/libcollections/str.rs
+10
-1
src/libcollections/string.rs
src/libcollections/string.rs
+3
-2
未找到文件。
src/doc/unstable-book/src/SUMMARY.md
浏览文件 @
c66c6e96
...
...
@@ -207,6 +207,7 @@
-
[
str_checked_slicing
](
library-features/str-checked-slicing.md
)
-
[
str_escape
](
library-features/str-escape.md
)
-
[
str_internals
](
library-features/str-internals.md
)
-
[
str_box_extras
](
library-features/str-box-extras.md
)
-
[
str_mut_extras
](
library-features/str-mut-extras.md
)
-
[
test
](
library-features/test.md
)
-
[
thread_id
](
library-features/thread-id.md
)
...
...
src/doc/unstable-book/src/library-features/str-box-extras.md
0 → 100644
浏览文件 @
c66c6e96
# `str_box_extras`
The tracking issue for this feature is: [#str_box_extras]
[
#str_box_extras
]:
https://github.com/rust-lang/rust/issues/41119
------------------------
src/liballoc/boxed.rs
浏览文件 @
c66c6e96
...
...
@@ -68,6 +68,7 @@
use
core
::
ops
::{
BoxPlace
,
Boxed
,
InPlace
,
Place
,
Placer
};
use
core
::
ptr
::{
self
,
Unique
};
use
core
::
convert
::
From
;
use
str
::
from_boxed_utf8_unchecked
;
/// A value that represents the heap. This is the default place that the `box`
/// keyword allocates into when no place is supplied.
...
...
@@ -320,8 +321,7 @@ fn default() -> Box<[T]> {
#[stable(feature
=
"default_box_extra"
,
since
=
"1.17.0"
)]
impl
Default
for
Box
<
str
>
{
fn
default
()
->
Box
<
str
>
{
let
default
:
Box
<
[
u8
]
>
=
Default
::
default
();
unsafe
{
mem
::
transmute
(
default
)
}
unsafe
{
from_boxed_utf8_unchecked
(
Default
::
default
())
}
}
}
...
...
@@ -366,7 +366,7 @@ fn clone(&self) -> Self {
let
buf
=
RawVec
::
with_capacity
(
len
);
unsafe
{
ptr
::
copy_nonoverlapping
(
self
.as_ptr
(),
buf
.ptr
(),
len
);
mem
::
transmute
(
buf
.into_box
())
// bytes to str ~magic
from_boxed_utf8_unchecked
(
buf
.into_box
())
}
}
}
...
...
@@ -441,8 +441,16 @@ fn from(slice: &'a [T]) -> Box<[T]> {
#[stable(feature
=
"box_from_slice"
,
since
=
"1.17.0"
)]
impl
<
'a
>
From
<&
'a
str
>
for
Box
<
str
>
{
fn
from
(
s
:
&
'a
str
)
->
Box
<
str
>
{
let
boxed
:
Box
<
[
u8
]
>
=
Box
::
from
(
s
.as_bytes
());
unsafe
{
mem
::
transmute
(
boxed
)
}
unsafe
{
from_boxed_utf8_unchecked
(
Box
::
from
(
s
.as_bytes
()))
}
}
}
#[stable(feature
=
"boxed_str_conv"
,
since
=
"1.18.0"
)]
impl
From
<
Box
<
str
>>
for
Box
<
[
u8
]
>
{
fn
from
(
s
:
Box
<
str
>
)
->
Self
{
unsafe
{
mem
::
transmute
(
s
)
}
}
}
...
...
src/liballoc/lib.rs
浏览文件 @
c66c6e96
...
...
@@ -128,6 +128,8 @@ mod boxed {
pub
mod
arc
;
pub
mod
rc
;
pub
mod
raw_vec
;
#[unstable(feature
=
"str_box_extras"
,
issue
=
"41119"
)]
pub
mod
str
;
pub
mod
oom
;
pub
use
oom
::
oom
;
src/liballoc/str.rs
0 → 100644
浏览文件 @
c66c6e96
// Copyright 2012-2017 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.
//! Methods for dealing with boxed strings.
use
core
::
mem
;
use
boxed
::
Box
;
/// Converts a boxed slice of bytes to a boxed string slice without checking
/// that the string contains valid UTF-8.
#[unstable(feature
=
"str_box_extras"
,
issue
=
"41119"
)]
pub
unsafe
fn
from_boxed_utf8_unchecked
(
v
:
Box
<
[
u8
]
>
)
->
Box
<
str
>
{
mem
::
transmute
(
v
)
}
src/libcollections/lib.rs
浏览文件 @
c66c6e96
...
...
@@ -60,6 +60,7 @@
#![feature(specialization)]
#![feature(staged_api)]
#![feature(str_internals)]
#![feature(str_box_extras)]
#![feature(str_mut_extras)]
#![feature(trusted_len)]
#![feature(unicode)]
...
...
src/libcollections/str.rs
浏览文件 @
c66c6e96
...
...
@@ -70,14 +70,17 @@
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
core
::
str
::{
MatchIndices
,
RMatchIndices
};
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
core
::
str
::{
from_utf8
,
Chars
,
CharIndices
,
Bytes
};
pub
use
core
::
str
::{
from_utf8
,
from_utf8_mut
,
Chars
,
CharIndices
,
Bytes
};
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
core
::
str
::{
from_utf8_unchecked
,
from_utf8_unchecked_mut
,
ParseBoolError
};
#[unstable(feature
=
"str_box_extras"
,
issue
=
"41119"
)]
pub
use
alloc
::
str
::
from_boxed_utf8_unchecked
;
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
std_unicode
::
str
::
SplitWhitespace
;
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
core
::
str
::
pattern
;
#[unstable(feature
=
"slice_concat_ext"
,
reason
=
"trait should not have to exist"
,
issue
=
"27747"
)]
...
...
@@ -1715,6 +1718,12 @@ pub fn parse<F: FromStr>(&self) -> Result<F, F::Err> {
core_str
::
StrExt
::
parse
(
self
)
}
/// Converts a `Box<str>` into a `Box<[u8]>` without copying or allocating.
#[unstable(feature
=
"str_box_extras"
,
issue
=
"41119"
)]
pub
fn
into_boxed_bytes
(
self
:
Box
<
str
>
)
->
Box
<
[
u8
]
>
{
self
.into
()
}
/// Replaces all matches of a pattern with another string.
///
/// `replace` creates a new [`String`], and copies the data from this string slice into it.
...
...
src/libcollections/string.rs
浏览文件 @
c66c6e96
...
...
@@ -56,10 +56,11 @@
#![stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
use
alloc
::
str
as
alloc_str
;
use
core
::
fmt
;
use
core
::
hash
;
use
core
::
iter
::{
FromIterator
,
FusedIterator
};
use
core
::
mem
;
use
core
::
ops
::{
self
,
Add
,
AddAssign
,
Index
,
IndexMut
};
use
core
::
ptr
;
use
core
::
str
as
core_str
;
...
...
@@ -1398,7 +1399,7 @@ pub fn drain<R>(&mut self, range: R) -> Drain
#[stable(feature
=
"box_str"
,
since
=
"1.4.0"
)]
pub
fn
into_boxed_str
(
self
)
->
Box
<
str
>
{
let
slice
=
self
.vec
.into_boxed_slice
();
unsafe
{
mem
::
transmute
::
<
Box
<
[
u8
]
>
,
Box
<
str
>>
(
slice
)
}
unsafe
{
alloc_str
::
from_boxed_utf8_unchecked
(
slice
)
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录