Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
28bcef85
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,发现更多精彩内容 >>
提交
28bcef85
编写于
5月 14, 2014
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libserialize: Remove all uses of `~str` from `libserialize`.
Had to make `struct Tm` in `libtime` not serializable for now.
上级
67e39a8e
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
316 addition
and
275 deletion
+316
-275
src/librustdoc/lib.rs
src/librustdoc/lib.rs
+9
-8
src/libserialize/base64.rs
src/libserialize/base64.rs
+25
-19
src/libserialize/ebml.rs
src/libserialize/ebml.rs
+24
-11
src/libserialize/hex.rs
src/libserialize/hex.rs
+8
-7
src/libserialize/json.rs
src/libserialize/json.rs
+232
-204
src/libserialize/serialize.rs
src/libserialize/serialize.rs
+2
-14
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+1
-1
src/libsyntax/parse/token.rs
src/libsyntax/parse/token.rs
+2
-1
src/libtest/lib.rs
src/libtest/lib.rs
+3
-3
src/libtime/lib.rs
src/libtime/lib.rs
+1
-1
src/libuuid/lib.rs
src/libuuid/lib.rs
+1
-1
src/libworkcache/lib.rs
src/libworkcache/lib.rs
+7
-4
src/test/run-pass/issue-2804.rs
src/test/run-pass/issue-2804.rs
+1
-1
未找到文件。
src/librustdoc/lib.rs
浏览文件 @
28bcef85
...
...
@@ -364,7 +364,7 @@ fn json_input(input: &str) -> Result<Output, StrBuf> {
Ok
(
json
::
Object
(
obj
))
=>
{
let
mut
obj
=
obj
;
// Make sure the schema is what we expect
match
obj
.pop
(
&
"schema"
.to_
owned
())
{
match
obj
.pop
(
&
"schema"
.to_
strbuf
())
{
Some
(
json
::
String
(
version
))
=>
{
if
version
.as_slice
()
!=
SCHEMA_VERSION
{
return
Err
(
format_strbuf!
(
...
...
@@ -375,7 +375,7 @@ fn json_input(input: &str) -> Result<Output, StrBuf> {
Some
(
..
)
=>
return
Err
(
"malformed json"
.to_strbuf
()),
None
=>
return
Err
(
"expected a schema version"
.to_strbuf
()),
}
let
krate
=
match
obj
.pop
(
&
"crate"
.to_str
())
{
let
krate
=
match
obj
.pop
(
&
"crate"
.to_str
buf
())
{
Some
(
json
)
=>
{
let
mut
d
=
json
::
Decoder
::
new
(
json
);
Decodable
::
decode
(
&
mut
d
)
.unwrap
()
...
...
@@ -404,13 +404,14 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
// "plugins": { output of plugins ... }
// }
let
mut
json
=
box
collections
::
TreeMap
::
new
();
json
.insert
(
"schema"
.to_owned
(),
json
::
String
(
SCHEMA_VERSION
.to_owned
()));
json
.insert
(
"schema"
.to_strbuf
(),
json
::
String
(
SCHEMA_VERSION
.to_strbuf
()));
let
plugins_json
=
box
res
.move_iter
()
.filter_map
(|
opt
|
{
match
opt
{
None
=>
None
,
Some
((
string
,
json
))
=>
{
Some
((
string
.to_
owned
(),
json
))
Some
((
string
.to_
strbuf
(),
json
))
}
}
})
.collect
();
...
...
@@ -423,15 +424,15 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
let
mut
encoder
=
json
::
Encoder
::
new
(
&
mut
w
as
&
mut
io
::
Writer
);
krate
.encode
(
&
mut
encoder
)
.unwrap
();
}
str
::
from_utf8
(
w
.unwrap
()
.as_slice
())
.unwrap
()
.to_
owned
()
str
::
from_utf8
(
w
.unwrap
()
.as_slice
())
.unwrap
()
.to_
strbuf
()
};
let
crate_json
=
match
json
::
from_str
(
crate_json_str
)
{
let
crate_json
=
match
json
::
from_str
(
crate_json_str
.as_slice
()
)
{
Ok
(
j
)
=>
j
,
Err
(
e
)
=>
fail
!
(
"Rust generated JSON is invalid: {:?}"
,
e
)
};
json
.insert
(
"crate"
.to_
owned
(),
crate_json
);
json
.insert
(
"plugins"
.to_
owned
(),
json
::
Object
(
plugins_json
));
json
.insert
(
"crate"
.to_
strbuf
(),
crate_json
);
json
.insert
(
"plugins"
.to_
strbuf
(),
json
::
Object
(
plugins_json
));
let
mut
file
=
try!
(
File
::
create
(
&
dst
));
try!
(
json
::
Object
(
json
)
.to_writer
(
&
mut
file
));
...
...
src/libserialize/base64.rs
浏览文件 @
28bcef85
...
...
@@ -54,7 +54,7 @@ pub struct Config {
pub
trait
ToBase64
{
/// Converts the value of `self` to a base64 value following the specified
/// format configuration, returning the owned string.
fn
to_base64
(
&
self
,
config
:
Config
)
->
~
str
;
fn
to_base64
(
&
self
,
config
:
Config
)
->
StrBuf
;
}
impl
<
'a
>
ToBase64
for
&
'a
[
u8
]
{
...
...
@@ -73,7 +73,7 @@ impl<'a> ToBase64 for &'a [u8] {
* }
* ```
*/
fn
to_base64
(
&
self
,
config
:
Config
)
->
~
str
{
fn
to_base64
(
&
self
,
config
:
Config
)
->
StrBuf
{
let
bytes
=
match
config
.char_set
{
Standard
=>
STANDARD_CHARS
,
UrlSafe
=>
URLSAFE_CHARS
...
...
@@ -146,7 +146,7 @@ fn to_base64(&self, config: Config) -> ~str {
}
unsafe
{
str
::
raw
::
from_utf8
(
v
.as_slice
())
.to_
owned
()
str
::
raw
::
from_utf8
(
v
.as_slice
())
.to_
strbuf
()
}
}
}
...
...
@@ -195,7 +195,7 @@ impl<'a> FromBase64 for &'a str {
* fn main () {
* let hello_str = bytes!("Hello, World").to_base64(STANDARD);
* println!("base64 output: {}", hello_str);
* let res = hello_str.from_base64();
* let res = hello_str.
as_slice().
from_base64();
* if res.is_ok() {
* let opt_bytes = StrBuf::from_utf8(res.unwrap());
* if opt_bytes.is_ok() {
...
...
@@ -267,34 +267,35 @@ mod tests {
#[test]
fn
test_to_base64_basic
()
{
assert_eq!
(
""
.as_bytes
()
.to_base64
(
STANDARD
),
""
.to_
owned
());
assert_eq!
(
"f"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zg=="
.to_
owned
());
assert_eq!
(
"fo"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm8="
.to_
owned
());
assert_eq!
(
"foo"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9v"
.to_
owned
());
assert_eq!
(
"foob"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYg=="
.to_
owned
());
assert_eq!
(
"fooba"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYmE="
.to_
owned
());
assert_eq!
(
"foobar"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYmFy"
.to_
owned
());
assert_eq!
(
""
.as_bytes
()
.to_base64
(
STANDARD
),
""
.to_
strbuf
());
assert_eq!
(
"f"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zg=="
.to_
strbuf
());
assert_eq!
(
"fo"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm8="
.to_
strbuf
());
assert_eq!
(
"foo"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9v"
.to_
strbuf
());
assert_eq!
(
"foob"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYg=="
.to_
strbuf
());
assert_eq!
(
"fooba"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYmE="
.to_
strbuf
());
assert_eq!
(
"foobar"
.as_bytes
()
.to_base64
(
STANDARD
),
"Zm9vYmFy"
.to_
strbuf
());
}
#[test]
fn
test_to_base64_line_break
()
{
assert
!
(
!
[
0u8
,
..
1000
]
.to_base64
(
Config
{
line_length
:
None
,
..
STANDARD
})
.contains
(
"
\r\n
"
));
.as_slice
()
.contains
(
"
\r\n
"
));
assert_eq!
(
"foobar"
.as_bytes
()
.to_base64
(
Config
{
line_length
:
Some
(
4
),
..
STANDARD
}),
"Zm9v
\r\n
YmFy"
.to_
owned
());
"Zm9v
\r\n
YmFy"
.to_
strbuf
());
}
#[test]
fn
test_to_base64_padding
()
{
assert_eq!
(
"f"
.as_bytes
()
.to_base64
(
Config
{
pad
:
false
,
..
STANDARD
}),
"Zg"
.to_
owned
());
assert_eq!
(
"fo"
.as_bytes
()
.to_base64
(
Config
{
pad
:
false
,
..
STANDARD
}),
"Zm8"
.to_
owned
());
assert_eq!
(
"f"
.as_bytes
()
.to_base64
(
Config
{
pad
:
false
,
..
STANDARD
}),
"Zg"
.to_
strbuf
());
assert_eq!
(
"fo"
.as_bytes
()
.to_base64
(
Config
{
pad
:
false
,
..
STANDARD
}),
"Zm8"
.to_
strbuf
());
}
#[test]
fn
test_to_base64_url_safe
()
{
assert_eq!
([
251
,
255
]
.to_base64
(
URL_SAFE
),
"-_8"
.to_
owned
());
assert_eq!
([
251
,
255
]
.to_base64
(
STANDARD
),
"+/8="
.to_
owned
());
assert_eq!
([
251
,
255
]
.to_base64
(
URL_SAFE
),
"-_8"
.to_
strbuf
());
assert_eq!
([
251
,
255
]
.to_base64
(
STANDARD
),
"+/8="
.to_
strbuf
());
}
#[test]
...
...
@@ -339,7 +340,12 @@ fn test_base64_random() {
for
_
in
range
(
0
,
1000
)
{
let
times
=
task_rng
()
.gen_range
(
1u
,
100
);
let
v
=
Vec
::
from_fn
(
times
,
|
_
|
random
::
<
u8
>
());
assert_eq!
(
v
.as_slice
()
.to_base64
(
STANDARD
)
.from_base64
()
.unwrap
()
.as_slice
(),
assert_eq!
(
v
.as_slice
()
.to_base64
(
STANDARD
)
.as_slice
()
.from_base64
()
.unwrap
()
.as_slice
(),
v
.as_slice
());
}
}
...
...
@@ -360,7 +366,7 @@ pub fn bench_from_base64(b: &mut Bencher) {
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"
;
let
sb
=
s
.as_bytes
()
.to_base64
(
STANDARD
);
b
.iter
(||
{
sb
.from_base64
()
.unwrap
();
sb
.
as_slice
()
.
from_base64
()
.unwrap
();
});
b
.bytes
=
sb
.len
()
as
u64
;
}
...
...
src/libserialize/ebml.rs
浏览文件 @
28bcef85
...
...
@@ -34,8 +34,8 @@ pub fn as_str_slice<'a>(&'a self) -> &'a str {
str
::
from_utf8
(
self
.data
.slice
(
self
.start
,
self
.end
))
.unwrap
()
}
pub
fn
as_str
(
&
self
)
->
~
str
{
self
.as_str_slice
()
.to_
owned
()
pub
fn
as_str
(
&
self
)
->
StrBuf
{
self
.as_str_slice
()
.to_
strbuf
()
}
}
...
...
@@ -80,7 +80,7 @@ pub enum EbmlEncoderTag {
#[deriving(Show)]
pub
enum
Error
{
IntTooBig
(
uint
),
Expected
(
~
str
),
Expected
(
StrBuf
),
IoError
(
io
::
IoError
)
}
// --------------------------------------
...
...
@@ -312,7 +312,10 @@ fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
self
.pos
=
r_doc
.end
;
let
str
=
r_doc
.as_str_slice
();
if
lbl
!=
str
{
return
Err
(
Expected
(
format!
(
"Expected label {} but found {}"
,
lbl
,
str
)));
return
Err
(
Expected
(
format_strbuf!
(
"Expected label
\
{} but found {}"
,
lbl
,
str
)));
}
}
}
...
...
@@ -322,7 +325,8 @@ fn _check_label(&mut self, lbl: &str) -> DecodeResult<()> {
fn
next_doc
(
&
mut
self
,
exp_tag
:
EbmlEncoderTag
)
->
DecodeResult
<
Doc
<
'doc
>>
{
debug!
(
". next_doc(exp_tag={:?})"
,
exp_tag
);
if
self
.pos
>=
self
.parent.end
{
return
Err
(
Expected
(
format!
(
"no more documents in current node!"
)));
return
Err
(
Expected
(
format_strbuf!
(
"no more documents in
\
current node!"
)));
}
let
TaggedDoc
{
tag
:
r_tag
,
doc
:
r_doc
}
=
try!
(
doc_at
(
self
.parent.data
,
self
.pos
));
...
...
@@ -334,12 +338,18 @@ fn next_doc(&mut self, exp_tag: EbmlEncoderTag) -> DecodeResult<Doc<'doc>> {
r_doc
.start
,
r_doc
.end
);
if
r_tag
!=
(
exp_tag
as
uint
)
{
return
Err
(
Expected
(
format!
(
"expected EBML doc with tag {:?} but found tag {:?}"
,
exp_tag
,
r_tag
)));
return
Err
(
Expected
(
format_strbuf!
(
"expected EBML doc with
\
tag {:?} but found tag
\
{:?}"
,
exp_tag
,
r_tag
)));
}
if
r_doc
.end
>
self
.parent.end
{
return
Err
(
Expected
(
format!
(
"invalid EBML, child extends to {:#x}, parent to {:#x}"
,
r_doc
.end
,
self
.parent.end
)));
return
Err
(
Expected
(
format_strbuf!
(
"invalid EBML, child
\
extends to {:#x}, parent
\
to {:#x}"
,
r_doc
.end
,
self
.parent.end
)));
}
self
.pos
=
r_doc
.end
;
Ok
(
r_doc
)
...
...
@@ -433,7 +443,7 @@ fn read_f32(&mut self) -> DecodeResult<f32> {
fn
read_char
(
&
mut
self
)
->
DecodeResult
<
char
>
{
Ok
(
char
::
from_u32
(
doc_as_u32
(
try!
(
self
.next_doc
(
EsChar
))))
.unwrap
())
}
fn
read_str
(
&
mut
self
)
->
DecodeResult
<
~
str
>
{
fn
read_str
(
&
mut
self
)
->
DecodeResult
<
StrBuf
>
{
Ok
(
try!
(
self
.next_doc
(
EsStr
))
.as_str
())
}
...
...
@@ -570,7 +580,10 @@ fn read_option<T>(&mut self,
match
idx
{
0
=>
f
(
this
,
false
),
1
=>
f
(
this
,
true
),
_
=>
Err
(
Expected
(
format!
(
"Expected None or Some"
))),
_
=>
{
Err
(
Expected
(
format_strbuf!
(
"Expected None or
\
Some"
)))
}
}
})
})
...
...
src/libserialize/hex.rs
浏览文件 @
28bcef85
...
...
@@ -16,7 +16,7 @@
pub
trait
ToHex
{
/// Converts the value of `self` to a hex value, returning the owned
/// string.
fn
to_hex
(
&
self
)
->
~
str
;
fn
to_hex
(
&
self
)
->
StrBuf
;
}
static
CHARS
:
&
'static
[
u8
]
=
bytes!
(
"0123456789abcdef"
);
...
...
@@ -37,7 +37,7 @@ impl<'a> ToHex for &'a [u8] {
* }
* ```
*/
fn
to_hex
(
&
self
)
->
~
str
{
fn
to_hex
(
&
self
)
->
StrBuf
{
let
mut
v
=
Vec
::
with_capacity
(
self
.len
()
*
2
);
for
&
byte
in
self
.iter
()
{
v
.push
(
CHARS
[(
byte
>>
4
)
as
uint
]);
...
...
@@ -45,7 +45,7 @@ fn to_hex(&self) -> ~str {
}
unsafe
{
str
::
raw
::
from_utf8
(
v
.as_slice
())
.to_
owned
()
str
::
raw
::
from_utf8
(
v
.as_slice
())
.to_
strbuf
()
}
}
}
...
...
@@ -94,7 +94,7 @@ impl<'a> FromHex for &'a str {
* fn main () {
* let hello_str = "Hello, World".as_bytes().to_hex();
* println!("{}", hello_str);
* let bytes = hello_str.from_hex().unwrap();
* let bytes = hello_str.
as_slice().
from_hex().unwrap();
* println!("{:?}", bytes);
* let result_str = StrBuf::from_utf8(bytes).unwrap();
* println!("{}", result_str);
...
...
@@ -143,7 +143,7 @@ mod tests {
#[test]
pub
fn
test_to_hex
()
{
assert_eq!
(
"foobar"
.as_bytes
()
.to_hex
(),
"666f6f626172"
.to_
owned
());
assert_eq!
(
"foobar"
.as_bytes
()
.to_hex
(),
"666f6f626172"
.to_
strbuf
());
}
#[test]
...
...
@@ -174,7 +174,8 @@ pub fn test_from_hex_ignores_whitespace() {
#[test]
pub
fn
test_to_hex_all_bytes
()
{
for
i
in
range
(
0
,
256
)
{
assert_eq!
([
i
as
u8
]
.to_hex
(),
format!
(
"{:02x}"
,
i
as
uint
));
assert_eq!
([
i
as
u8
]
.to_hex
(),
format_strbuf!
(
"{:02x}"
,
i
as
uint
));
}
}
...
...
@@ -202,7 +203,7 @@ pub fn bench_from_hex(b: &mut Bencher) {
ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン"
;
let
sb
=
s
.as_bytes
()
.to_hex
();
b
.iter
(||
{
sb
.from_hex
()
.unwrap
();
sb
.
as_slice
()
.
from_hex
()
.unwrap
();
});
b
.bytes
=
sb
.len
()
as
u64
;
}
...
...
src/libserialize/json.rs
浏览文件 @
28bcef85
此差异已折叠。
点击以展开。
src/libserialize/serialize.rs
浏览文件 @
28bcef85
...
...
@@ -108,7 +108,7 @@ pub trait Decoder<E> {
fn
read_f64
(
&
mut
self
)
->
Result
<
f64
,
E
>
;
fn
read_f32
(
&
mut
self
)
->
Result
<
f32
,
E
>
;
fn
read_char
(
&
mut
self
)
->
Result
<
char
,
E
>
;
fn
read_str
(
&
mut
self
)
->
Result
<
~
str
,
E
>
;
fn
read_str
(
&
mut
self
)
->
Result
<
StrBuf
,
E
>
;
// Compound types:
fn
read_enum
<
T
>
(
&
mut
self
,
name
:
&
str
,
f
:
|
&
mut
Self
|
->
Result
<
T
,
E
>
)
->
Result
<
T
,
E
>
;
...
...
@@ -301,18 +301,6 @@ fn encode(&self, s: &mut S) -> Result<(), E> {
}
}
impl
<
E
,
S
:
Encoder
<
E
>>
Encodable
<
S
,
E
>
for
~
str
{
fn
encode
(
&
self
,
s
:
&
mut
S
)
->
Result
<
(),
E
>
{
s
.emit_str
(
*
self
)
}
}
impl
<
E
,
D
:
Decoder
<
E
>>
Decodable
<
D
,
E
>
for
~
str
{
fn
decode
(
d
:
&
mut
D
)
->
Result
<~
str
,
E
>
{
d
.read_str
()
}
}
impl
<
E
,
S
:
Encoder
<
E
>>
Encodable
<
S
,
E
>
for
StrBuf
{
fn
encode
(
&
self
,
s
:
&
mut
S
)
->
Result
<
(),
E
>
{
s
.emit_str
(
self
.as_slice
())
...
...
@@ -321,7 +309,7 @@ fn encode(&self, s: &mut S) -> Result<(), E> {
impl
<
E
,
D
:
Decoder
<
E
>>
Decodable
<
D
,
E
>
for
StrBuf
{
fn
decode
(
d
:
&
mut
D
)
->
Result
<
StrBuf
,
E
>
{
Ok
(
StrBuf
::
from_str
(
try!
(
d
.read_str
())))
Ok
(
StrBuf
::
from_str
(
try!
(
d
.read_str
())
.as_slice
()
))
}
}
...
...
src/libsyntax/ast.rs
浏览文件 @
28bcef85
...
...
@@ -106,7 +106,7 @@ fn encode(&self, s: &mut S) -> Result<(), E> {
impl
<
D
:
Decoder
<
E
>
,
E
>
Decodable
<
D
,
E
>
for
Ident
{
fn
decode
(
d
:
&
mut
D
)
->
Result
<
Ident
,
E
>
{
Ok
(
str_to_ident
(
try!
(
d
.read_str
())))
Ok
(
str_to_ident
(
try!
(
d
.read_str
())
.as_slice
()
))
}
}
...
...
src/libsyntax/parse/token.rs
浏览文件 @
28bcef85
...
...
@@ -606,7 +606,8 @@ fn equiv(&self, other: & &'a str) -> bool {
impl
<
D
:
Decoder
<
E
>
,
E
>
Decodable
<
D
,
E
>
for
InternedString
{
fn
decode
(
d
:
&
mut
D
)
->
Result
<
InternedString
,
E
>
{
Ok
(
get_name
(
get_ident_interner
()
.intern
(
try!
(
d
.read_str
()))))
Ok
(
get_name
(
get_ident_interner
()
.intern
(
try!
(
d
.read_str
())
.as_slice
())))
}
}
...
...
src/libtest/lib.rs
浏览文件 @
28bcef85
...
...
@@ -1067,8 +1067,8 @@ fn calc_result(desc: &TestDesc, task_succeeded: bool) -> TestResult {
impl
ToJson
for
Metric
{
fn
to_json
(
&
self
)
->
json
::
Json
{
let
mut
map
=
box
TreeMap
::
new
();
map
.insert
(
"value"
.to_
owned
(),
json
::
Number
(
self
.value
));
map
.insert
(
"noise"
.to_
owned
(),
json
::
Number
(
self
.noise
));
map
.insert
(
"value"
.to_
strbuf
(),
json
::
Number
(
self
.value
));
map
.insert
(
"noise"
.to_
strbuf
(),
json
::
Number
(
self
.noise
));
json
::
Object
(
map
)
}
}
...
...
@@ -1105,7 +1105,7 @@ pub fn save(&self, p: &Path) -> io::IoResult<()> {
// FIXME(pcwalton): Yuck.
let
mut
new_map
=
TreeMap
::
new
();
for
(
ref
key
,
ref
value
)
in
map
.iter
()
{
new_map
.insert
(
key
.to_
owned
(),
(
*
value
)
.clone
());
new_map
.insert
(
key
.to_
strbuf
(),
(
*
value
)
.clone
());
}
new_map
.to_json
()
.to_pretty_writer
(
&
mut
file
)
...
...
src/libtime/lib.rs
浏览文件 @
28bcef85
...
...
@@ -189,7 +189,7 @@ pub fn tzset() {
/// Holds a calendar date and time broken down into its components (year, month, day, and so on),
/// also called a broken-down time value.
#[deriving(Clone,
Eq,
Encodable,
Decodable,
Show)]
#[deriving(Clone,
Eq,
Show)]
pub
struct
Tm
{
/// Seconds after the minute – [0, 60]
pub
tm_sec
:
i32
,
...
...
src/libuuid/lib.rs
浏览文件 @
28bcef85
...
...
@@ -500,7 +500,7 @@ fn encode(&self, e: &mut T) -> Result<(), E> {
impl
<
T
:
Decoder
<
E
>
,
E
>
Decodable
<
T
,
E
>
for
Uuid
{
/// Decode a UUID from a string
fn
decode
(
d
:
&
mut
T
)
->
Result
<
Uuid
,
E
>
{
Ok
(
from_str
(
try!
(
d
.read_str
()))
.unwrap
())
Ok
(
from_str
(
try!
(
d
.read_str
())
.as_slice
()
)
.unwrap
())
}
}
...
...
src/libworkcache/lib.rs
浏览文件 @
28bcef85
...
...
@@ -192,7 +192,7 @@ fn save(&self) -> io::IoResult<()> {
// FIXME(pcwalton): Yuck.
let
mut
new_db_cache
=
TreeMap
::
new
();
for
(
ref
k
,
ref
v
)
in
self
.db_cache
.iter
()
{
new_db_cache
.insert
((
*
k
)
.to_
owned
(),
(
*
v
)
.to_owned
());
new_db_cache
.insert
((
*
k
)
.to_
strbuf
(),
(
*
v
)
.to_strbuf
());
}
new_db_cache
.to_json
()
.to_pretty_writer
(
&
mut
f
)
...
...
@@ -515,10 +515,13 @@ fn make_path(filename: StrBuf) -> Path {
let
pth
=
pth
.clone
();
let
contents
=
File
::
open
(
&
pth
)
.read_to_end
()
.unwrap
();
let
file_content
=
from_utf8
(
contents
.as_slice
())
.unwrap
()
.to_owned
();
let
file_content
=
from_utf8
(
contents
.as_slice
())
.unwrap
()
.to_strbuf
();
// FIXME (#9639): This needs to handle non-utf8 paths
prep
.declare_input
(
"file"
,
pth
.as_str
()
.unwrap
(),
file_content
);
prep
.declare_input
(
"file"
,
pth
.as_str
()
.unwrap
(),
file_content
.as_slice
());
prep
.exec
(
proc
(
_
exe
)
{
let
out
=
make_path
(
"foo.o"
.to_strbuf
());
let
compiler
=
if
cfg!
(
windows
)
{
"gcc"
}
else
{
"cc"
};
...
...
@@ -528,7 +531,7 @@ fn make_path(filename: StrBuf) -> Path {
// Could run sub-rules inside here.
// FIXME (#9639): This needs to handle non-utf8 paths
out
.as_str
()
.unwrap
()
.to_
owned
()
out
.as_str
()
.unwrap
()
.to_
strbuf
()
})
});
...
...
src/test/run-pass/issue-2804.rs
浏览文件 @
28bcef85
...
...
@@ -23,7 +23,7 @@ enum object {
fn
lookup
(
table
:
Box
<
json
::
Object
>
,
key
:
StrBuf
,
default
:
StrBuf
)
->
StrBuf
{
match
table
.find
(
&
key
.to_
owned
())
{
match
table
.find
(
&
key
.to_
strbuf
())
{
option
::
Some
(
&
json
::
String
(
ref
s
))
=>
{
(
*
s
)
.to_strbuf
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录