Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2da9856f
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,发现更多精彩内容 >>
提交
2da9856f
编写于
3月 21, 2021
作者:
M
Mara Bos
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add internal io::Error::new_const tot avoid allocations.
上级
f398a498
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
0 deletion
+26
-0
library/std/src/io/error.rs
library/std/src/io/error.rs
+26
-0
未找到文件。
library/std/src/io/error.rs
浏览文件 @
2da9856f
...
...
@@ -69,6 +69,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
enum
Repr
{
Os
(
i32
),
Simple
(
ErrorKind
),
// &str is a fat pointer, but &&str is a thin pointer.
SimpleMessage
(
ErrorKind
,
&
'static
&
'static
str
),
Custom
(
Box
<
Custom
>
),
}
...
...
@@ -259,6 +261,18 @@ fn _new(kind: ErrorKind, error: Box<dyn error::Error + Send + Sync>) -> Error {
Error
{
repr
:
Repr
::
Custom
(
Box
::
new
(
Custom
{
kind
,
error
}))
}
}
/// Creates a new I/O error from a known kind of error as well as a
/// constant message.
///
/// This function not allocate.
///
/// This function should maybe change to
/// `new_const<const MSG: &'static str>(kind: ErrorKind)`
/// in the future, when const generics allows that.
pub
(
crate
)
const
fn
new_const
(
kind
:
ErrorKind
,
message
:
&
'static
&
'static
str
)
->
Error
{
Self
{
repr
:
Repr
::
SimpleMessage
(
kind
,
message
)
}
}
/// Returns an error representing the last OS error which occurred.
///
/// This function reads the value of `errno` for the target platform (e.g.
...
...
@@ -342,6 +356,7 @@ pub fn raw_os_error(&self) -> Option<i32> {
Repr
::
Os
(
i
)
=>
Some
(
i
),
Repr
::
Custom
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
}
}
...
...
@@ -377,6 +392,7 @@ pub fn get_ref(&self) -> Option<&(dyn error::Error + Send + Sync + 'static)> {
match
self
.repr
{
Repr
::
Os
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
Repr
::
Custom
(
ref
c
)
=>
Some
(
&*
c
.error
),
}
}
...
...
@@ -448,6 +464,7 @@ pub fn get_mut(&mut self) -> Option<&mut (dyn error::Error + Send + Sync + 'stat
match
self
.repr
{
Repr
::
Os
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
Repr
::
Custom
(
ref
mut
c
)
=>
Some
(
&
mut
*
c
.error
),
}
}
...
...
@@ -484,6 +501,7 @@ pub fn into_inner(self) -> Option<Box<dyn error::Error + Send + Sync>> {
match
self
.repr
{
Repr
::
Os
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
Repr
::
Custom
(
c
)
=>
Some
(
c
.error
),
}
}
...
...
@@ -512,6 +530,7 @@ pub fn kind(&self) -> ErrorKind {
Repr
::
Os
(
code
)
=>
sys
::
decode_error_kind
(
code
),
Repr
::
Custom
(
ref
c
)
=>
c
.kind
,
Repr
::
Simple
(
kind
)
=>
kind
,
Repr
::
SimpleMessage
(
kind
,
_
)
=>
kind
,
}
}
}
...
...
@@ -527,6 +546,9 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
.finish
(),
Repr
::
Custom
(
ref
c
)
=>
fmt
::
Debug
::
fmt
(
&
c
,
fmt
),
Repr
::
Simple
(
kind
)
=>
fmt
.debug_tuple
(
"Kind"
)
.field
(
&
kind
)
.finish
(),
Repr
::
SimpleMessage
(
kind
,
&
message
)
=>
{
fmt
.debug_struct
(
"Error"
)
.field
(
"kind"
,
&
kind
)
.field
(
"message"
,
&
message
)
.finish
()
}
}
}
}
...
...
@@ -541,6 +563,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
}
Repr
::
Custom
(
ref
c
)
=>
c
.error
.fmt
(
fmt
),
Repr
::
Simple
(
kind
)
=>
write!
(
fmt
,
"{}"
,
kind
.as_str
()),
Repr
::
SimpleMessage
(
_
,
&
msg
)
=>
msg
.fmt
(
fmt
),
}
}
}
...
...
@@ -551,6 +574,7 @@ impl error::Error for Error {
fn
description
(
&
self
)
->
&
str
{
match
self
.repr
{
Repr
::
Os
(
..
)
|
Repr
::
Simple
(
..
)
=>
self
.kind
()
.as_str
(),
Repr
::
SimpleMessage
(
_
,
&
msg
)
=>
msg
,
Repr
::
Custom
(
ref
c
)
=>
c
.error
.description
(),
}
}
...
...
@@ -560,6 +584,7 @@ fn cause(&self) -> Option<&dyn error::Error> {
match
self
.repr
{
Repr
::
Os
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
Repr
::
Custom
(
ref
c
)
=>
c
.error
.cause
(),
}
}
...
...
@@ -568,6 +593,7 @@ fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match
self
.repr
{
Repr
::
Os
(
..
)
=>
None
,
Repr
::
Simple
(
..
)
=>
None
,
Repr
::
SimpleMessage
(
..
)
=>
None
,
Repr
::
Custom
(
ref
c
)
=>
c
.error
.source
(),
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录