From 3cf15fb7f36eb90de23d411a33c8a41984dccb15 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 12 Jun 2014 06:31:47 -0700 Subject: [PATCH] Update to rust HEAD --- json.rs | 269 ------------------------------------------------------- serde.rs | 2 +- 2 files changed, 1 insertion(+), 270 deletions(-) diff --git a/json.rs b/json.rs index e3605667..5331275e 100644 --- a/json.rs +++ b/json.rs @@ -1994,20 +1994,6 @@ pub fn from_json< de::Deserializable::deserialize(&mut d) } -/// A structure to decode JSON to values in rust. -pub struct Decoder { - stack: Vec, -} - -impl Decoder { - /// Creates a new decoder instance for decoding the specified JSON value. - pub fn new(json: Json) -> Decoder { - Decoder { - stack: vec!(json), - } - } -} - macro_rules! expect( ($e:expr, Null) => ({ match $e { @@ -2027,257 +2013,6 @@ macro_rules! expect( }) ) - /* -impl ::Decoder for Decoder { - - fn read_nil(&mut self) -> DecodeResult<()> { - debug!("read_nil"); - try!(expect!(self.pop(), Null)); - Ok(()) - } - - fn read_u64(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as u64) } - fn read_u32(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as u32) } - fn read_u16(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as u16) } - fn read_u8 (&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as u8) } - fn read_uint(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as uint) } - - fn read_i64(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as i64) } - fn read_i32(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as i32) } - fn read_i16(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as i16) } - fn read_i8 (&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as i8) } - fn read_int(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as int) } - - fn read_bool(&mut self) -> DecodeResult { - debug!("read_bool"); - Ok(try!(expect!(self.pop(), Boolean))) - } - - fn read_f64(&mut self) -> DecodeResult { - use std::from_str::FromStr; - debug!("read_f64"); - match self.pop() { - Number(f) => Ok(f), - String(s) => { - // re: #12967.. a type w/ numeric keys (ie HashMap etc) - // is going to have a string here, as per JSON spec.. - Ok(FromStr::from_str(s.as_slice()).unwrap()) - }, - value => { - Err(ExpectedError("Number".to_string(), - format!("{}", value))) - } - } - } - - fn read_f32(&mut self) -> DecodeResult { Ok(try!(self.read_f64()) as f32) } - - fn read_char(&mut self) -> DecodeResult { - let s = try!(self.read_str()); - { - let mut it = s.as_slice().chars(); - match (it.next(), it.next()) { - // exactly one character - (Some(c), None) => return Ok(c), - _ => () - } - } - Err(ExpectedError("single character string".to_string(), - format!("{}", s))) - } - - fn read_str(&mut self) -> DecodeResult { - debug!("read_str"); - Ok(try!(expect!(self.pop(), String))) - } - - fn read_enum(&mut self, - name: &str, - f: |&mut Decoder| -> DecodeResult) -> DecodeResult { - debug!("read_enum({})", name); - f(self) - } - - fn read_enum_variant(&mut self, - names: &[&str], - f: |&mut Decoder, uint| -> DecodeResult) - -> DecodeResult { - debug!("read_enum_variant(names={:?})", names); - let name = match self.pop() { - String(s) => s, - Object(mut o) => { - let n = match o.pop(&"variant".to_string()) { - Some(String(s)) => s, - Some(val) => { - return Err(ExpectedError("String".to_string(), - format!("{}", val))) - } - None => { - return Err(MissingFieldError("variant".to_string())) - } - }; - match o.pop(&"fields".to_string()) { - Some(List(l)) => { - for field in l.move_iter().rev() { - self.stack.push(field.clone()); - } - }, - Some(val) => { - return Err(ExpectedError("List".to_string(), - format!("{}", val))) - } - None => { - return Err(MissingFieldError("fields".to_string())) - } - } - n - } - json => { - return Err(ExpectedError("String or Object".to_string(), - format!("{}", json))) - } - }; - let idx = match names.iter() - .position(|n| { - str::eq_slice(*n, name.as_slice()) - }) { - Some(idx) => idx, - None => return Err(UnknownVariantError(name)) - }; - f(self, idx) - } - - fn read_enum_variant_arg(&mut self, idx: uint, f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_enum_variant_arg(idx={})", idx); - f(self) - } - - fn read_enum_struct_variant(&mut self, - names: &[&str], - f: |&mut Decoder, uint| -> DecodeResult) - -> DecodeResult { - debug!("read_enum_struct_variant(names={:?})", names); - self.read_enum_variant(names, f) - } - - - fn read_enum_struct_variant_field(&mut self, - name: &str, - idx: uint, - f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_enum_struct_variant_field(name={}, idx={})", name, idx); - self.read_enum_variant_arg(idx, f) - } - - fn read_struct(&mut self, - name: &str, - len: uint, - f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_struct(name={}, len={})", name, len); - let value = try!(f(self)); - self.pop(); - Ok(value) - } - - fn read_struct_field(&mut self, - name: &str, - idx: uint, - f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_struct_field(name={}, idx={})", name, idx); - let mut obj = try!(expect!(self.pop(), Object)); - - let value = match obj.pop(&name.to_string()) { - None => return Err(MissingFieldError(name.to_string())), - Some(json) => { - self.stack.push(json); - try!(f(self)) - } - }; - self.stack.push(Object(obj)); - Ok(value) - } - - fn read_tuple(&mut self, f: |&mut Decoder, uint| -> DecodeResult) -> DecodeResult { - debug!("read_tuple()"); - self.read_seq(f) - } - - fn read_tuple_arg(&mut self, - idx: uint, - f: |&mut Decoder| -> DecodeResult) -> DecodeResult { - debug!("read_tuple_arg(idx={})", idx); - self.read_seq_elt(idx, f) - } - - fn read_tuple_struct(&mut self, - name: &str, - f: |&mut Decoder, uint| -> DecodeResult) - -> DecodeResult { - debug!("read_tuple_struct(name={})", name); - self.read_tuple(f) - } - - fn read_tuple_struct_arg(&mut self, - idx: uint, - f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_tuple_struct_arg(idx={})", idx); - self.read_tuple_arg(idx, f) - } - - fn read_option(&mut self, f: |&mut Decoder, bool| -> DecodeResult) -> DecodeResult { - match self.pop() { - Null => f(self, false), - value => { self.stack.push(value); f(self, true) } - } - } - - fn read_seq(&mut self, f: |&mut Decoder, uint| -> DecodeResult) -> DecodeResult { - debug!("read_seq()"); - let list = try!(expect!(self.pop(), List)); - let len = list.len(); - for v in list.move_iter().rev() { - self.stack.push(v); - } - f(self, len) - } - - fn read_seq_elt(&mut self, - idx: uint, - f: |&mut Decoder| -> DecodeResult) -> DecodeResult { - debug!("read_seq_elt(idx={})", idx); - f(self) - } - - fn read_map(&mut self, f: |&mut Decoder, uint| -> DecodeResult) -> DecodeResult { - debug!("read_map()"); - let obj = try!(expect!(self.pop(), Object)); - let len = obj.len(); - for (key, value) in obj.move_iter() { - self.stack.push(value); - self.stack.push(String(key)); - } - f(self, len) - } - - fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_map_elt_key(idx={})", idx); - f(self) - } - - fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder| -> DecodeResult) - -> DecodeResult { - debug!("read_map_elt_val(idx={})", idx); - f(self) - } -} - */ - /// Test if two json values are less than one another impl PartialOrd for Json { fn lt(&self, other: &Json) -> bool { @@ -2428,10 +2163,6 @@ impl ToJson for (A, B, C) { } } -impl ToJson for ~[A] { - fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) } -} - impl ToJson for Vec { fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) } } diff --git a/serde.rs b/serde.rs index e079a3f5..856e8199 100644 --- a/serde.rs +++ b/serde.rs @@ -4,7 +4,7 @@ #[cfg(test)] extern crate test; -#[phase(syntax, link)] +#[phase(plugin, link)] extern crate log; #[cfg(test)]