Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2c4a1b55
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,发现更多精彩内容 >>
提交
2c4a1b55
编写于
12月 03, 2013
作者:
K
Kevin Ballard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename extra::json::*::init() constructors to *::new()
上级
408dc5ad
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
57 addition
and
57 deletion
+57
-57
src/libextra/json.rs
src/libextra/json.rs
+48
-48
src/libextra/test.rs
src/libextra/test.rs
+1
-1
src/libextra/workcache.rs
src/libextra/workcache.rs
+3
-3
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+2
-2
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+1
-1
src/test/run-pass/issue-4016.rs
src/test/run-pass/issue-4016.rs
+1
-1
src/test/run-pass/issue-4036.rs
src/test/run-pass/issue-4036.rs
+1
-1
未找到文件。
src/libextra/json.rs
浏览文件 @
2c4a1b55
...
...
@@ -91,7 +91,7 @@ pub struct Encoder<'self> {
impl
<
'self
>
Encoder
<
'self
>
{
/// Creates a new JSON encoder whose output will be written to the writer
/// specified.
pub
fn
init
<
'a
>
(
wr
:
&
'a
mut
io
::
Writer
)
->
Encoder
<
'a
>
{
pub
fn
new
<
'a
>
(
wr
:
&
'a
mut
io
::
Writer
)
->
Encoder
<
'a
>
{
Encoder
{
wr
:
wr
}
}
}
...
...
@@ -247,7 +247,7 @@ pub struct PrettyEncoder<'self> {
impl
<
'self
>
PrettyEncoder
<
'self
>
{
/// Creates a new encoder whose output will be written to the specified writer
pub
fn
init
<
'a
>
(
wr
:
&
'a
mut
io
::
Writer
)
->
PrettyEncoder
<
'a
>
{
pub
fn
new
<
'a
>
(
wr
:
&
'a
mut
io
::
Writer
)
->
PrettyEncoder
<
'a
>
{
PrettyEncoder
{
wr
:
wr
,
indent
:
0
,
...
...
@@ -449,14 +449,14 @@ fn encode(&self, e: &mut E) {
impl
Json
{
/// Encodes a json value into a io::writer. Uses a single line.
pub
fn
to_writer
(
&
self
,
wr
:
&
mut
io
::
Writer
)
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
self
.encode
(
&
mut
encoder
)
}
/// Encodes a json value into a io::writer.
/// Pretty-prints in a more readable format.
pub
fn
to_pretty_writer
(
&
self
,
wr
:
&
mut
io
::
Writer
)
{
let
mut
encoder
=
PrettyEncoder
::
init
(
wr
);
let
mut
encoder
=
PrettyEncoder
::
new
(
wr
);
self
.encode
(
&
mut
encoder
)
}
...
...
@@ -477,7 +477,7 @@ pub struct Parser<T> {
impl
<
T
:
Iterator
<
char
>>
Parser
<
T
>
{
/// Decode a json value from an Iterator<char>
pub
fn
init
(
rdr
:
T
)
->
Parser
<
T
>
{
pub
fn
new
(
rdr
:
T
)
->
Parser
<
T
>
{
let
mut
p
=
Parser
{
rdr
:
rdr
,
ch
:
'\x00'
,
...
...
@@ -848,13 +848,13 @@ fn parse_object(&mut self) -> Result<Json, Error> {
/// Decodes a json value from an `&mut io::Reader`
pub
fn
from_reader
(
rdr
:
&
mut
io
::
Reader
)
->
Result
<
Json
,
Error
>
{
let
s
=
str
::
from_utf8_owned
(
rdr
.read_to_end
());
let
mut
parser
=
Parser
::
init
(
s
.chars
());
let
mut
parser
=
Parser
::
new
(
s
.chars
());
parser
.parse
()
}
/// Decodes a json value from a string
pub
fn
from_str
(
s
:
&
str
)
->
Result
<
Json
,
Error
>
{
let
mut
parser
=
Parser
::
init
(
s
.chars
());
let
mut
parser
=
Parser
::
new
(
s
.chars
());
parser
.parse
()
}
...
...
@@ -865,7 +865,7 @@ pub struct Decoder {
impl
Decoder
{
/// Creates a new decoder instance for decoding the specified JSON value.
pub
fn
init
(
json
:
Json
)
->
Decoder
{
pub
fn
new
(
json
:
Json
)
->
Decoder
{
Decoder
{
stack
:
~
[
json
]
}
...
...
@@ -1522,14 +1522,14 @@ fn test_write_enum() {
let
animal
=
Dog
;
assert_eq!
(
with_str_writer
(|
wr
|
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
animal
.encode
(
&
mut
encoder
);
}),
~
"
\"
Dog
\"
"
);
assert_eq!
(
with_str_writer
(|
wr
|
{
let
mut
encoder
=
PrettyEncoder
::
init
(
wr
);
let
mut
encoder
=
PrettyEncoder
::
new
(
wr
);
animal
.encode
(
&
mut
encoder
);
}),
~
"
\"
Dog
\"
"
...
...
@@ -1538,14 +1538,14 @@ fn test_write_enum() {
let
animal
=
Frog
(
~
"Henry"
,
349
);
assert_eq!
(
with_str_writer
(|
wr
|
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
animal
.encode
(
&
mut
encoder
);
}),
~
"{
\"
variant
\"
:
\"
Frog
\"
,
\"
fields
\"
:[
\"
Henry
\"
,349]}"
);
assert_eq!
(
with_str_writer
(|
wr
|
{
let
mut
encoder
=
PrettyEncoder
::
init
(
wr
);
let
mut
encoder
=
PrettyEncoder
::
new
(
wr
);
animal
.encode
(
&
mut
encoder
);
}),
~
"
\
...
...
@@ -1561,14 +1561,14 @@ fn test_write_enum() {
fn
test_write_some
()
{
let
value
=
Some
(
~
"jodhpurs"
);
let
s
=
with_str_writer
(|
wr
|
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
value
.encode
(
&
mut
encoder
);
});
assert_eq!
(
s
,
~
"
\"
jodhpurs
\"
"
);
let
value
=
Some
(
~
"jodhpurs"
);
let
s
=
with_str_writer
(|
wr
|
{
let
mut
encoder
=
PrettyEncoder
::
init
(
wr
);
let
mut
encoder
=
PrettyEncoder
::
new
(
wr
);
value
.encode
(
&
mut
encoder
);
});
assert_eq!
(
s
,
~
"
\"
jodhpurs
\"
"
);
...
...
@@ -1578,13 +1578,13 @@ fn test_write_some() {
fn
test_write_none
()
{
let
value
:
Option
<~
str
>
=
None
;
let
s
=
with_str_writer
(|
wr
|
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
value
.encode
(
&
mut
encoder
);
});
assert_eq!
(
s
,
~
"null"
);
let
s
=
with_str_writer
(|
wr
|
{
let
mut
encoder
=
Encoder
::
init
(
wr
);
let
mut
encoder
=
Encoder
::
new
(
wr
);
value
.encode
(
&
mut
encoder
);
});
assert_eq!
(
s
,
~
"null"
);
...
...
@@ -1633,15 +1633,15 @@ fn test_read_identifiers() {
#[test]
fn
test_decode_identifiers
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"null"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"null"
)
.unwrap
());
let
v
:
()
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
());
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"true"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"true"
)
.unwrap
());
let
v
:
bool
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
true
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"false"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"false"
)
.unwrap
());
let
v
:
bool
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
false
);
}
...
...
@@ -1676,31 +1676,31 @@ fn test_read_number() {
#[test]
fn
test_decode_numbers
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"3"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"3"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
3.0
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"3.1"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"3.1"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
3.1
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"-1.2"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"-1.2"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
-
1.2
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"0.4"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"0.4"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
0.4
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"0.4e5"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"0.4e5"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
0.4e5
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"0.4e15"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"0.4e15"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
0.4e15
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"0.4e-01"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"0.4e-01"
)
.unwrap
());
let
v
:
f64
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
0.4e-01
);
}
...
...
@@ -1728,39 +1728,39 @@ fn test_read_str() {
#[test]
fn
test_decode_str
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
""
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"
foo
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"
foo
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"foo"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\\"\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\\"\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\"
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
b
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
b
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\x08
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
n
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
n
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\n
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
r
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
r
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\r
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
t
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
t
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\t
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
u12ab
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
u12ab
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\u12ab
"
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"\\
uAB12
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"\\
uAB12
\"
"
)
.unwrap
());
let
v
:
~
str
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
"
\uAB12
"
);
}
...
...
@@ -1793,27 +1793,27 @@ fn test_read_list() {
#[test]
fn
test_decode_list
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[]"
)
.unwrap
());
let
v
:
~
[()]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[]);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[null]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[null]"
)
.unwrap
());
let
v
:
~
[()]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[()]);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[true]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[true]"
)
.unwrap
());
let
v
:
~
[
bool
]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[
true
]);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[true]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[true]"
)
.unwrap
());
let
v
:
~
[
bool
]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[
true
]);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[3, 1]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[3, 1]"
)
.unwrap
());
let
v
:
~
[
int
]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[
3
,
1
]);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"[[3], [1, 2]]"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"[[3], [1, 2]]"
)
.unwrap
());
let
v
:
~
[
~
[
uint
]]
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
~
[
~
[
3
],
~
[
1
,
2
]]);
}
...
...
@@ -1915,7 +1915,7 @@ fn test_decode_struct() {
{
\"
a
\"
: null,
\"
b
\"
: 2,
\"
c
\"
: [
\"
abc
\"
,
\"
xyz
\"
] }
]
}"
;
let
mut
decoder
=
Decoder
::
init
(
from_str
(
s
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
s
)
.unwrap
());
let
v
:
Outer
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
v
,
...
...
@@ -1929,23 +1929,23 @@ fn test_decode_struct() {
#[test]
fn
test_decode_option
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"null"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"null"
)
.unwrap
());
let
value
:
Option
<~
str
>
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
value
,
None
);
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"
jodhpurs
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"
jodhpurs
\"
"
)
.unwrap
());
let
value
:
Option
<~
str
>
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
value
,
Some
(
~
"jodhpurs"
));
}
#[test]
fn
test_decode_enum
()
{
let
mut
decoder
=
Decoder
::
init
(
from_str
(
"
\"
Dog
\"
"
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
"
\"
Dog
\"
"
)
.unwrap
());
let
value
:
Animal
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
value
,
Dog
);
let
s
=
"{
\"
variant
\"
:
\"
Frog
\"
,
\"
fields
\"
:[
\"
Henry
\"
,349]}"
;
let
mut
decoder
=
Decoder
::
init
(
from_str
(
s
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
s
)
.unwrap
());
let
value
:
Animal
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
value
,
Frog
(
~
"Henry"
,
349
));
}
...
...
@@ -1953,7 +1953,7 @@ fn test_decode_enum() {
#[test]
fn
test_decode_map
()
{
let
s
=
~
"{
\"
a
\"
:
\"
Dog
\"
,
\"
b
\"
: {
\"
variant
\"
:
\"
Frog
\"
,
\"
fields
\"
:[
\"
Henry
\"
, 349]}}"
;
let
mut
decoder
=
Decoder
::
init
(
from_str
(
s
)
.unwrap
());
let
mut
decoder
=
Decoder
::
new
(
from_str
(
s
)
.unwrap
());
let
mut
map
:
TreeMap
<~
str
,
Animal
>
=
Decodable
::
decode
(
&
mut
decoder
);
assert_eq!
(
map
.pop
(
&~
"a"
),
Some
(
Dog
));
...
...
@@ -1990,7 +1990,7 @@ fn check_err<T: Decodable<Decoder>>(to_parse: &'static str, expected_error: &str
match
from_str
(
to_parse
)
{
Err
(
e
)
=>
Some
(
e
.to_str
()),
Ok
(
json
)
=>
{
let
_
:
T
=
Decodable
::
decode
(
&
mut
Decoder
::
init
(
json
));
let
_
:
T
=
Decodable
::
decode
(
&
mut
Decoder
::
new
(
json
));
None
}
}
...
...
src/libextra/test.rs
浏览文件 @
2c4a1b55
...
...
@@ -947,7 +947,7 @@ pub fn load(p: &Path) -> MetricMap {
assert
!
(
p
.exists
());
let
mut
f
=
File
::
open
(
p
);
let
value
=
json
::
from_reader
(
&
mut
f
as
&
mut
io
::
Reader
)
.unwrap
();
let
mut
decoder
=
json
::
Decoder
::
init
(
value
);
let
mut
decoder
=
json
::
Decoder
::
new
(
value
);
MetricMap
(
Decodable
::
decode
(
&
mut
decoder
))
}
...
...
src/libextra/workcache.rs
浏览文件 @
2c4a1b55
...
...
@@ -191,7 +191,7 @@ fn load(&mut self) {
Err
(
e
)
=>
fail
!
(
"Couldn't parse workcache database (from file {}): {}"
,
self
.db_filename
.display
(),
e
.to_str
()),
Ok
(
r
)
=>
{
let
mut
decoder
=
json
::
Decoder
::
init
(
r
);
let
mut
decoder
=
json
::
Decoder
::
new
(
r
);
self
.db_cache
=
Decodable
::
decode
(
&
mut
decoder
);
}
}
...
...
@@ -258,7 +258,7 @@ enum Work<'self, T> {
fn
json_encode
<
'self
,
T
:
Encodable
<
json
::
Encoder
<
'self
>>>
(
t
:
&
T
)
->
~
str
{
let
mut
writer
=
MemWriter
::
new
();
let
mut
encoder
=
json
::
Encoder
::
init
(
&
mut
writer
as
&
mut
io
::
Writer
);
let
mut
encoder
=
json
::
Encoder
::
new
(
&
mut
writer
as
&
mut
io
::
Writer
);
t
.encode
(
&
mut
encoder
);
str
::
from_utf8_owned
(
writer
.inner
())
}
...
...
@@ -267,7 +267,7 @@ fn json_encode<'self, T:Encodable<json::Encoder<'self>>>(t: &T) -> ~str {
fn
json_decode
<
T
:
Decodable
<
json
::
Decoder
>>
(
s
:
&
str
)
->
T
{
debug!
(
"json decoding: {}"
,
s
);
let
j
=
json
::
from_str
(
s
)
.unwrap
();
let
mut
decoder
=
json
::
Decoder
::
init
(
j
);
let
mut
decoder
=
json
::
Decoder
::
new
(
j
);
Decodable
::
decode
(
&
mut
decoder
)
}
...
...
src/librustdoc/lib.rs
浏览文件 @
2c4a1b55
...
...
@@ -283,7 +283,7 @@ fn json_input(input: &str) -> Result<Output, ~str> {
}
let
crate
=
match
obj
.pop
(
&~
"crate"
)
{
Some
(
json
)
=>
{
let
mut
d
=
json
::
Decoder
::
init
(
json
);
let
mut
d
=
json
::
Decoder
::
new
(
json
);
Decodable
::
decode
(
&
mut
d
)
}
None
=>
return
Err
(
~
"malformed json"
),
...
...
@@ -314,7 +314,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
let
crate_json_str
=
{
let
mut
w
=
MemWriter
::
new
();
{
let
mut
encoder
=
json
::
Encoder
::
init
(
&
mut
w
as
&
mut
io
::
Writer
);
let
mut
encoder
=
json
::
Encoder
::
new
(
&
mut
w
as
&
mut
io
::
Writer
);
crate
.encode
(
&
mut
encoder
);
}
str
::
from_utf8_owned
(
w
.inner
())
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
2c4a1b55
...
...
@@ -344,7 +344,7 @@ mod test {
#[cfg(test)]
fn
to_json_str
<
'a
,
E
:
Encodable
<
extra
::
json
::
Encoder
<
'a
>>>
(
val
:
&
E
)
->
~
str
{
let
mut
writer
=
MemWriter
::
new
();
let
mut
encoder
=
extra
::
json
::
Encoder
::
init
(
&
mut
writer
as
&
mut
io
::
Writer
);
let
mut
encoder
=
extra
::
json
::
Encoder
::
new
(
&
mut
writer
as
&
mut
io
::
Writer
);
val
.encode
(
&
mut
encoder
);
str
::
from_utf8_owned
(
writer
.inner
())
}
...
...
src/test/run-pass/issue-4016.rs
浏览文件 @
2c4a1b55
...
...
@@ -18,7 +18,7 @@ trait JD : Decodable<json::Decoder> { }
fn
exec
<
T
:
JD
>
()
{
let
doc
=
json
::
from_str
(
""
)
.unwrap
();
let
mut
decoder
=
json
::
Decoder
::
init
(
doc
);
let
mut
decoder
=
json
::
Decoder
::
new
(
doc
);
let
_
v
:
T
=
Decodable
::
decode
(
&
mut
decoder
);
fail
!
()
}
...
...
src/test/run-pass/issue-4036.rs
浏览文件 @
2c4a1b55
...
...
@@ -17,6 +17,6 @@
pub
fn
main
()
{
let
json
=
json
::
from_str
(
"[1]"
)
.unwrap
();
let
mut
decoder
=
json
::
Decoder
::
init
(
json
);
let
mut
decoder
=
json
::
Decoder
::
new
(
json
);
let
_
x
:
~
[
int
]
=
serialize
::
Decodable
::
decode
(
&
mut
decoder
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录