Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
10490210
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,发现更多精彩内容 >>
提交
10490210
编写于
9月 09, 2015
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reduce code bloat from conversion traits in function parameters
上级
0762f58c
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
101 addition
and
28 deletion
+101
-28
src/librustc_back/tempdir.rs
src/librustc_back/tempdir.rs
+5
-1
src/libstd/env.rs
src/libstd/env.rs
+19
-3
src/libstd/ffi/c_str.rs
src/libstd/ffi/c_str.rs
+4
-1
src/libstd/ffi/os_str.rs
src/libstd/ffi/os_str.rs
+10
-10
src/libstd/fs.rs
src/libstd/fs.rs
+18
-5
src/libstd/io/error.rs
src/libstd/io/error.rs
+5
-1
src/libstd/path.rs
src/libstd/path.rs
+40
-7
未找到文件。
src/librustc_back/tempdir.rs
浏览文件 @
10490210
...
...
@@ -38,8 +38,12 @@ impl TempDir {
#[allow(deprecated)]
// rand usage
pub
fn
new_in
<
P
:
AsRef
<
Path
>>
(
tmpdir
:
P
,
prefix
:
&
str
)
->
io
::
Result
<
TempDir
>
{
Self
::
_
new_in
(
tmpdir
.as_ref
(),
prefix
)
}
fn
_
new_in
(
tmpdir
:
&
Path
,
prefix
:
&
str
)
->
io
::
Result
<
TempDir
>
{
let
storage
;
let
mut
tmpdir
=
tmpdir
.as_ref
()
;
let
mut
tmpdir
=
tmpdir
;
if
!
tmpdir
.is_absolute
()
{
let
cur_dir
=
try!
(
env
::
current_dir
());
storage
=
cur_dir
.join
(
tmpdir
);
...
...
src/libstd/env.rs
浏览文件 @
10490210
...
...
@@ -174,6 +174,10 @@ fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
/// ```
#[stable(feature
=
"env"
,
since
=
"1.0.0"
)]
pub
fn
var
<
K
:
AsRef
<
OsStr
>>
(
key
:
K
)
->
Result
<
String
,
VarError
>
{
_
var
(
key
.as_ref
())
}
fn
_
var
(
key
:
&
OsStr
)
->
Result
<
String
,
VarError
>
{
match
var_os
(
key
)
{
Some
(
s
)
=>
s
.into_string
()
.map_err
(
VarError
::
NotUnicode
),
None
=>
Err
(
VarError
::
NotPresent
)
...
...
@@ -196,8 +200,12 @@ pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
/// ```
#[stable(feature
=
"env"
,
since
=
"1.0.0"
)]
pub
fn
var_os
<
K
:
AsRef
<
OsStr
>>
(
key
:
K
)
->
Option
<
OsString
>
{
_
var_os
(
key
.as_ref
())
}
fn
_
var_os
(
key
:
&
OsStr
)
->
Option
<
OsString
>
{
let
_
g
=
ENV_LOCK
.lock
();
os_imp
::
getenv
(
key
.as_ref
()
)
os_imp
::
getenv
(
key
)
}
/// Possible errors from the `env::var` method.
...
...
@@ -263,8 +271,12 @@ fn description(&self) -> &str {
/// ```
#[stable(feature
=
"env"
,
since
=
"1.0.0"
)]
pub
fn
set_var
<
K
:
AsRef
<
OsStr
>
,
V
:
AsRef
<
OsStr
>>
(
k
:
K
,
v
:
V
)
{
_
set_var
(
k
.as_ref
(),
v
.as_ref
())
}
fn
_
set_var
(
k
:
&
OsStr
,
v
:
&
OsStr
)
{
let
_
g
=
ENV_LOCK
.lock
();
os_imp
::
setenv
(
k
.as_ref
(),
v
.as_ref
()
)
os_imp
::
setenv
(
k
,
v
)
}
/// Removes an environment variable from the environment of the currently running process.
...
...
@@ -294,8 +306,12 @@ pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(k: K, v: V) {
/// ```
#[stable(feature
=
"env"
,
since
=
"1.0.0"
)]
pub
fn
remove_var
<
K
:
AsRef
<
OsStr
>>
(
k
:
K
)
{
_
remove_var
(
k
.as_ref
())
}
fn
_
remove_var
(
k
:
&
OsStr
)
{
let
_
g
=
ENV_LOCK
.lock
();
os_imp
::
unsetenv
(
k
.as_ref
()
)
os_imp
::
unsetenv
(
k
)
}
/// An iterator over `Path` instances for parsing an environment variable
...
...
src/libstd/ffi/c_str.rs
浏览文件 @
10490210
...
...
@@ -181,7 +181,10 @@ impl CString {
/// the position of the nul byte.
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
new
<
T
:
Into
<
Vec
<
u8
>>>
(
t
:
T
)
->
Result
<
CString
,
NulError
>
{
let
bytes
=
t
.into
();
Self
::
_
new
(
t
.into
())
}
fn
_
new
(
bytes
:
Vec
<
u8
>
)
->
Result
<
CString
,
NulError
>
{
match
bytes
.iter
()
.position
(|
x
|
*
x
==
0
)
{
Some
(
i
)
=>
Err
(
NulError
(
i
,
bytes
)),
None
=>
Ok
(
unsafe
{
CString
::
from_vec_unchecked
(
bytes
)
}),
...
...
src/libstd/ffi/os_str.rs
浏览文件 @
10490210
...
...
@@ -73,20 +73,20 @@ pub fn new() -> OsString {
/// convert; non UTF-8 data will produce `None`.
#[unstable(feature
=
"convert"
,
reason
=
"recently added"
,
issue
=
"27704"
)]
pub
fn
from_bytes
<
B
>
(
bytes
:
B
)
->
Option
<
OsString
>
where
B
:
Into
<
Vec
<
u8
>>
{
Self
::
_
from_bytes
(
bytes
.into
())
}
#[cfg(unix)]
fn
from_bytes_inner
(
vec
:
Vec
<
u8
>
)
->
Option
<
OsString
>
{
fn
_
from_bytes
(
vec
:
Vec
<
u8
>
)
->
Option
<
OsString
>
{
use
os
::
unix
::
ffi
::
OsStringExt
;
Some
(
OsString
::
from_vec
(
vec
))
}
#[cfg(windows)]
fn
from_bytes_inner
(
vec
:
Vec
<
u8
>
)
->
Option
<
OsString
>
{
fn
_
from_bytes
(
vec
:
Vec
<
u8
>
)
->
Option
<
OsString
>
{
String
::
from_utf8
(
vec
)
.ok
()
.map
(
OsString
::
from
)
}
from_bytes_inner
(
bytes
.into
())
}
/// Converts to an `OsStr` slice.
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
as_os_str
(
&
self
)
->
&
OsStr
{
...
...
src/libstd/fs.rs
浏览文件 @
10490210
...
...
@@ -184,7 +184,7 @@ impl File {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
open
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
io
::
Result
<
File
>
{
OpenOptions
::
new
()
.read
(
true
)
.open
(
path
)
OpenOptions
::
new
()
.read
(
true
)
.open
(
path
.as_ref
()
)
}
/// Opens a file in write-only mode.
...
...
@@ -206,7 +206,7 @@ pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
create
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
io
::
Result
<
File
>
{
OpenOptions
::
new
()
.write
(
true
)
.create
(
true
)
.truncate
(
true
)
.open
(
path
)
OpenOptions
::
new
()
.write
(
true
)
.create
(
true
)
.truncate
(
true
)
.open
(
path
.as_ref
()
)
}
/// Attempts to sync all OS-internal metadata to disk.
...
...
@@ -494,7 +494,10 @@ pub fn create(&mut self, create: bool) -> &mut OpenOptions {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
open
<
P
:
AsRef
<
Path
>>
(
&
self
,
path
:
P
)
->
io
::
Result
<
File
>
{
let
path
=
path
.as_ref
();
self
._open
(
path
.as_ref
())
}
fn
_
open
(
&
self
,
path
:
&
Path
)
->
io
::
Result
<
File
>
{
let
inner
=
try!
(
fs_imp
::
File
::
open
(
path
,
&
self
.0
));
Ok
(
File
{
inner
:
inner
})
}
...
...
@@ -1048,7 +1051,10 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
remove_dir_all
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
io
::
Result
<
()
>
{
let
path
=
path
.as_ref
();
_
remove_dir_all
(
path
.as_ref
())
}
fn
_
remove_dir_all
(
path
:
&
Path
)
->
io
::
Result
<
()
>
{
for
child
in
try!
(
read_dir
(
path
))
{
let
child
=
try!
(
child
)
.path
();
let
stat
=
try!
(
symlink_metadata
(
&*
child
));
...
...
@@ -1113,6 +1119,10 @@ pub fn read_dir<P: AsRef<Path>>(path: P) -> io::Result<ReadDir> {
as symlinks differently"
,
issue
=
"27707"
)]
pub
fn
walk_dir
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
io
::
Result
<
WalkDir
>
{
_
walk_dir
(
path
.as_ref
())
}
fn
_
walk_dir
(
path
:
&
Path
)
->
io
::
Result
<
WalkDir
>
{
let
start
=
try!
(
read_dir
(
path
));
Ok
(
WalkDir
{
cur
:
Some
(
start
),
stack
:
Vec
::
new
()
})
}
...
...
@@ -1272,7 +1282,10 @@ pub fn recursive(&mut self, recursive: bool) -> &mut Self {
/// Create the specified directory with the options configured in this
/// builder.
pub
fn
create
<
P
:
AsRef
<
Path
>>
(
&
self
,
path
:
P
)
->
io
::
Result
<
()
>
{
let
path
=
path
.as_ref
();
self
._create
(
path
.as_ref
())
}
fn
_
create
(
&
self
,
path
:
&
Path
)
->
io
::
Result
<
()
>
{
if
self
.recursive
{
self
.create_dir_all
(
path
)
}
else
{
...
...
src/libstd/io/error.rs
浏览文件 @
10490210
...
...
@@ -191,10 +191,14 @@ impl Error {
pub
fn
new
<
E
>
(
kind
:
ErrorKind
,
error
:
E
)
->
Error
where
E
:
Into
<
Box
<
error
::
Error
+
Send
+
Sync
>>
{
Self
::
_
new
(
kind
,
error
.into
())
}
fn
_
new
(
kind
:
ErrorKind
,
error
:
Box
<
error
::
Error
+
Send
+
Sync
>
)
->
Error
{
Error
{
repr
:
Repr
::
Custom
(
Box
::
new
(
Custom
{
kind
:
kind
,
error
:
error
.into
()
,
error
:
error
,
}))
}
}
...
...
src/libstd/path.rs
浏览文件 @
10490210
...
...
@@ -965,8 +965,10 @@ pub fn as_path(&self) -> &Path {
/// * if `path` has a prefix but no root, it replaces `self`.
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn push<P: AsRef<Path>>(&mut self, path: P) {
let path = path.as_ref();
self._push(path.as_ref())
}
fn _push(&mut self, path: &Path) {
// in general, a separator is needed if the rightmost byte is not a separator
let mut need_sep = self.as_mut_vec().last().map(|c| !is_sep_byte(*c)).unwrap_or(false);
...
...
@@ -1033,11 +1035,15 @@ pub fn pop(&mut self) -> bool {
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S) {
self._set_file_name(file_name.as_ref())
}
fn _set_file_name(&mut self, file_name: &OsStr) {
if self.file_name().is_some() {
let popped = self.pop();
debug_assert!(popped);
}
self.push(file_name
.as_ref()
);
self.push(file_name);
}
/// Updates `self.extension()` to `extension`.
...
...
@@ -1048,6 +1054,10 @@ pub fn set_file_name<S: AsRef<OsStr>>(&mut self, file_name: S) {
/// is added; otherwise it is replaced.
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool {
self._set_extension(extension.as_ref())
}
fn _set_extension(&mut self, extension: &OsStr) -> bool {
if self.file_name().is_none() { return false; }
let mut stem = match self.file_stem() {
...
...
@@ -1055,7 +1065,6 @@ pub fn set_extension<S: AsRef<OsStr>>(&mut self, extension: S) -> bool {
None => OsString::new(),
};
let extension = extension.as_ref();
if !os_str_as_u8_slice(extension).is_empty() {
stem.push("
.
");
stem.push(extension);
...
...
@@ -1106,7 +1115,7 @@ fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {
impl<P: AsRef<Path>> iter::Extend<P> for PathBuf {
fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I) {
for p in iter {
self.push(p)
self.push(p
.as_ref()
)
}
}
}
...
...
@@ -1452,7 +1461,11 @@ pub fn file_name(&self) -> Option<&OsStr> {
issue = "
23284
")]
pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Option<&Path>
{
iter_after(self.components(), base.as_ref().components()).map(|c| c.as_path())
self._relative_from(base.as_ref())
}
fn _relative_from<'a>(&'a self, base: &'a Path) -> Option<&'a Path> {
iter_after(self.components(), base.components()).map(|c| c.as_path())
}
/// Determines whether `base` is a prefix of `self`.
...
...
@@ -1472,7 +1485,11 @@ pub fn relative_from<'a, P: ?Sized + AsRef<Path>>(&'a self, base: &'a P) -> Opti
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool {
iter_after(self.components(), base.as_ref().components()).is_some()
self._starts_with(base.as_ref())
}
fn _starts_with(&self, base: &Path) -> bool {
iter_after(self.components(), base.components()).is_some()
}
/// Determines whether `child` is a suffix of `self`.
...
...
@@ -1490,7 +1507,11 @@ pub fn starts_with<P: AsRef<Path>>(&self, base: P) -> bool {
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {
iter_after(self.components().rev(), child.as_ref().components().rev()).is_some()
self._ends_with(child.as_ref())
}
fn _ends_with(&self, child: &Path) -> bool {
iter_after(self.components().rev(), child.components().rev()).is_some()
}
/// Extracts the stem (non-extension) portion of `self.file_name()`.
...
...
@@ -1552,6 +1573,10 @@ pub fn extension(&self) -> Option<&OsStr> {
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf {
self._join(path.as_ref())
}
fn _join(&self, path: &Path) -> PathBuf {
let mut buf = self.to_path_buf();
buf.push(path);
buf
...
...
@@ -1571,6 +1596,10 @@ pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf {
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf {
self._with_file_name(file_name.as_ref())
}
fn _with_file_name(&self, file_name: &OsStr) -> PathBuf {
let mut buf = self.to_path_buf();
buf.set_file_name(file_name);
buf
...
...
@@ -1590,6 +1619,10 @@ pub fn with_file_name<S: AsRef<OsStr>>(&self, file_name: S) -> PathBuf {
/// ```
#[stable(feature = "
rust1
", since = "
1.0
.0
")]
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {
self._with_extension(extension.as_ref())
}
fn _with_extension(&self, extension: &OsStr) -> PathBuf {
let mut buf = self.to_path_buf();
buf.set_extension(extension);
buf
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录