Skip to content

Commit 20c2625

Browse files
committed
---
yaml --- r: 80859 b: refs/heads/try c: 9ea295b h: refs/heads/master i: 80857: 1325805 80855: ea769d7 v: v3
1 parent c5d6b20 commit 20c2625

File tree

11 files changed

+41
-447
lines changed

11 files changed

+41
-447
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
5-
refs/heads/try: 6bc48b63f376439801d43820f6df0990797b8787
5+
refs/heads/try: 9ea295b7df26c954cbb4f5f3c0dc669b14a2389d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libextra/json.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,21 @@ impl serialize::Encoder for Encoder {
135135
_id: uint,
136136
cnt: uint,
137137
f: &fn(&mut Encoder)) {
138-
// enums are encoded as strings or vectors:
138+
// enums are encoded as strings or objects
139139
// Bunny => "Bunny"
140-
// Kangaroo(34,"William") => ["Kangaroo",[34,"William"]]
141-
140+
// Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
142141
if cnt == 0 {
143142
self.wr.write_str(escape_str(name));
144143
} else {
145-
self.wr.write_char('[');
144+
self.wr.write_char('{');
145+
self.wr.write_str("\"variant\"");
146+
self.wr.write_char(':');
146147
self.wr.write_str(escape_str(name));
147148
self.wr.write_char(',');
149+
self.wr.write_str("\"fields\"");
150+
self.wr.write_str(":[");
148151
f(self);
149-
self.wr.write_char(']');
152+
self.wr.write_str("]}");
150153
}
151154
}
152155

@@ -947,14 +950,20 @@ impl serialize::Decoder for Decoder {
947950
debug!("read_enum_variant(names=%?)", names);
948951
let name = match self.stack.pop() {
949952
String(s) => s,
950-
List(list) => {
951-
for v in list.move_rev_iter() {
952-
self.stack.push(v);
953-
}
954-
match self.stack.pop() {
955-
String(s) => s,
956-
value => fail!("invalid variant name: %?", value),
953+
Object(o) => {
954+
let n = match o.find(&~"variant").expect("invalidly encoded json") {
955+
&String(ref s) => s.clone(),
956+
_ => fail!("invalidly encoded json"),
957+
};
958+
match o.find(&~"fields").expect("invalidly encoded json") {
959+
&List(ref l) => {
960+
for field in l.rev_iter() {
961+
self.stack.push(field.clone());
962+
}
963+
},
964+
_ => fail!("invalidly encoded json")
957965
}
966+
n
958967
}
959968
ref json => fail!("invalid variant: %?", *json),
960969
};
@@ -1517,7 +1526,7 @@ mod tests {
15171526
let mut encoder = Encoder(wr);
15181527
animal.encode(&mut encoder);
15191528
},
1520-
~"[\"Frog\",\"Henry\",349]"
1529+
~"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}"
15211530
);
15221531
assert_eq!(
15231532
do io::with_str_writer |wr| {
@@ -1921,14 +1930,14 @@ mod tests {
19211930
assert_eq!(value, Dog);
19221931

19231932
let mut decoder =
1924-
Decoder(from_str("[\"Frog\",\"Henry\",349]").unwrap());
1933+
Decoder(from_str("{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}").unwrap());
19251934
let value: Animal = Decodable::decode(&mut decoder);
19261935
assert_eq!(value, Frog(~"Henry", 349));
19271936
}
19281937
19291938
#[test]
19301939
fn test_decode_map() {
1931-
let s = ~"{\"a\": \"Dog\", \"b\": [\"Frog\", \"Henry\", 349]}";
1940+
let s = ~"{\"a\": \"Dog\", \"b\": {\"variant\":\"Frog\",\"fields\":[\"Henry\", 349]}}";
19321941
let mut decoder = Decoder(from_str(s).unwrap());
19331942
let mut map: TreeMap<~str, Animal> = Decodable::decode(&mut decoder);
19341943

branches/try/src/libstd/logging.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use option::*;
1414
use os;
1515
use rt;
16-
use rt::logging::{Logger, StdErrLogger};
17-
use send_str::SendStrOwned;
16+
use rt::logging::{Logger, StdErrLogger, OwnedString};
1817

1918
/// Turns on logging to stdout globally
2019
pub fn console_on() {
@@ -57,12 +56,12 @@ fn newsched_log_str(msg: ~str) {
5756
match optional_task {
5857
Some(local) => {
5958
// Use the available logger
60-
(*local).logger.log(SendStrOwned(msg));
59+
(*local).logger.log(OwnedString(msg));
6160
}
6261
None => {
6362
// There is no logger anywhere, just write to stderr
6463
let mut logger = StdErrLogger;
65-
logger.log(SendStrOwned(msg));
64+
logger.log(OwnedString(msg));
6665
}
6766
}
6867
}

branches/try/src/libstd/prelude.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ pub use path::PosixPath;
6666
pub use path::WindowsPath;
6767
pub use ptr::RawPtr;
6868
pub use ascii::{Ascii, AsciiCast, OwnedAsciiCast, AsciiStr, ToBytesConsume};
69-
pub use send_str::{SendStr, SendStrOwned, SendStrStatic, IntoSendStr};
7069
pub use str::{Str, StrVector, StrSlice, OwnedStr};
7170
pub use from_str::FromStr;
7271
pub use to_bytes::IterBytes;

branches/try/src/libstd/rt/logging.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use str::raw::from_c_str;
1717
use u32;
1818
use vec::ImmutableVector;
1919
use cast::transmute;
20-
use send_str::{SendStr, SendStrOwned, SendStrStatic};
2120

2221
struct LogDirective {
2322
name: Option<~str>,
@@ -169,26 +168,32 @@ fn update_log_settings(crate_map: *u8, settings: ~str) {
169168
}
170169
}
171170

171+
/// Represent a string with `Send` bound.
172+
pub enum SendableString {
173+
OwnedString(~str),
174+
StaticString(&'static str)
175+
}
176+
172177
pub trait Logger {
173-
fn log(&mut self, msg: SendStr);
178+
fn log(&mut self, msg: SendableString);
174179
}
175180

176181
pub struct StdErrLogger;
177182

178183
impl Logger for StdErrLogger {
179-
fn log(&mut self, msg: SendStr) {
184+
fn log(&mut self, msg: SendableString) {
180185
use io::{Writer, WriterUtil};
181186

182187
if !should_log_console() {
183188
return;
184189
}
185190

186191
let s: &str = match msg {
187-
SendStrOwned(ref s) => {
192+
OwnedString(ref s) => {
188193
let slc: &str = *s;
189194
slc
190195
},
191-
SendStrStatic(s) => s,
196+
StaticString(s) => s,
192197
};
193198

194199
// Truncate the string

0 commit comments

Comments
 (0)