From 58825221124db0edbdecef6a331a872a5e20dacb Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Mon, 15 Dec 2014 00:14:18 +0100 Subject: Update to last rust. --- src/parser.rs | 14 ++-- src/serialization.rs | 179 ++++++++++++++++++++++++++------------------------- 2 files changed, 100 insertions(+), 93 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 7b910d3..9143673 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -81,7 +81,7 @@ impl<'a> Parser<'a> { } fn next_pos(&self) -> uint { - self.cur.clone().next().map(|p| p.val0()).unwrap_or(self.input.len()) + self.cur.clone().next().map(|p| p.0).unwrap_or(self.input.len()) } // Returns true and consumes the next character if it matches `ch`, @@ -96,8 +96,8 @@ impl<'a> Parser<'a> { fn expect(&mut self, ch: char) -> bool { if self.eat(ch) { return true } let mut it = self.cur.clone(); - let lo = it.next().map(|p| p.val0()).unwrap_or(self.input.len()); - let hi = it.next().map(|p| p.val0()).unwrap_or(self.input.len()); + let lo = it.next().map(|p| p.0).unwrap_or(self.input.len()); + let hi = it.next().map(|p| p.0).unwrap_or(self.input.len()); self.errors.push(ParserError { lo: lo, hi: hi, @@ -258,8 +258,8 @@ impl<'a> Parser<'a> { Some((pos, ch)) if ch.is_digit(10) => self.number_or_datetime(pos), _ => { let mut it = self.cur.clone(); - let lo = it.next().map(|p| p.val0()).unwrap_or(self.input.len()); - let hi = it.next().map(|p| p.val0()).unwrap_or(self.input.len()); + let lo = it.next().map(|p| p.0).unwrap_or(self.input.len()); + let hi = it.next().map(|p| p.0).unwrap_or(self.input.len()); self.errors.push(ParserError { lo: lo, hi: hi, @@ -624,8 +624,8 @@ impl<'a> Parser<'a> { } } - fn recurse<'a>(&mut self, mut cur: &'a mut TomlTable, orig_key: &'a str, - key_lo: uint) -> Option<(&'a mut TomlTable, &'a str)> { + fn recurse<'b>(&mut self, mut cur: &'b mut TomlTable, orig_key: &'b str, + key_lo: uint) -> Option<(&'b mut TomlTable, &'b str)> { if orig_key.starts_with(".") || orig_key.ends_with(".") || orig_key.contains("..") { self.errors.push(ParserError { diff --git a/src/serialization.rs b/src/serialization.rs index 829d89a..1b9d02e 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -204,37 +204,45 @@ impl serialize::Encoder for Encoder { fn emit_str(&mut self, v: &str) -> Result<(), Error> { self.emit_value(Value::String(v.to_string())) } - fn emit_enum(&mut self, _name: &str, - f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> { + fn emit_enum(&mut self, _name: &str, f: F) + -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> + { f(self) } - fn emit_enum_variant(&mut self, _v_name: &str, _v_id: uint, _len: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_enum_variant(&mut self, _v_name: &str, _v_id: uint, _len: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_enum_variant_arg(&mut self, _a_idx: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_enum_variant_arg(&mut self, _a_idx: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_enum_struct_variant(&mut self, _v_name: &str, _v_id: uint, - _len: uint, - _f: |&mut Encoder| -> Result<(), Error>) + fn emit_enum_struct_variant(&mut self, _v_name: &str, _v_id: uint, + _len: uint, + _f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { panic!() } - fn emit_enum_struct_variant_field(&mut self, _f_name: &str, _f_idx: uint, - _f: |&mut Encoder| -> Result<(), Error>) + fn emit_enum_struct_variant_field(&mut self, + _f_name: &str, + _f_idx: uint, + _f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { panic!() } - fn emit_struct(&mut self, _name: &str, _len: uint, - f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> { + fn emit_struct(&mut self, _name: &str, _len: uint, f: F) + -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> + { match mem::replace(&mut self.state, Start) { NextKey(key) => { let mut nested = Encoder::new(); @@ -253,9 +261,9 @@ impl serialize::Encoder for Encoder { NextMapKey => Err(InvalidMapKeyLocation), } } - fn emit_struct_field(&mut self, f_name: &str, _f_idx: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_struct_field(&mut self, f_name: &str, _f_idx: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { let old = mem::replace(&mut self.state, NextKey(f_name.to_string())); try!(f(self)); @@ -265,31 +273,33 @@ impl serialize::Encoder for Encoder { self.state = old; Ok(()) } - fn emit_tuple(&mut self, len: uint, - f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> { + fn emit_tuple(&mut self, len: uint, f: F) + -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> + { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, idx: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_tuple_arg(&mut self, idx: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { self.emit_seq_elt(idx, f) } - fn emit_tuple_struct(&mut self, _name: &str, _len: uint, - _f: |&mut Encoder| -> Result<(), Error>) + fn emit_tuple_struct(&mut self, _name: &str, _len: uint, _f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { unimplemented!() } - fn emit_tuple_struct_arg(&mut self, _f_idx: uint, - _f: |&mut Encoder| -> Result<(), Error>) + fn emit_tuple_struct_arg(&mut self, _f_idx: uint, _f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { unimplemented!() } - fn emit_option(&mut self, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_option(&mut self, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } @@ -301,15 +311,15 @@ impl serialize::Encoder for Encoder { NextMapKey => Err(InvalidMapKeyLocation), } } - fn emit_option_some(&mut self, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_option_some(&mut self, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_seq(&mut self, _len: uint, - f: |this: &mut Encoder| -> Result<(), Error>) + fn emit_seq(&mut self, _len: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { let old = mem::replace(&mut self.state, NextArray(Vec::new())); try!(f(self)); @@ -318,19 +328,21 @@ impl serialize::Encoder for Encoder { _ => unreachable!(), } } - fn emit_seq_elt(&mut self, _idx: uint, - f: |this: &mut Encoder| -> Result<(), Error>) + fn emit_seq_elt(&mut self, _idx: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } - fn emit_map(&mut self, len: uint, - f: |&mut Encoder| -> Result<(), Error>) -> Result<(), Error> { + fn emit_map(&mut self, len: uint, f: F) + -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> + { self.emit_struct("foo", len, f) } - fn emit_map_elt_key(&mut self, _idx: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_map_elt_key(&mut self, _idx: uint, mut f: F) -> Result<(), Error> + where F: FnMut(&mut Encoder) -> Result<(), Error> { match mem::replace(&mut self.state, NextMapKey) { Start => {} @@ -342,9 +354,9 @@ impl serialize::Encoder for Encoder { _ => Err(InvalidMapKeyLocation), } } - fn emit_map_elt_val(&mut self, _idx: uint, - f: |&mut Encoder| -> Result<(), Error>) + fn emit_map_elt_val(&mut self, _idx: uint, f: F) -> Result<(), Error> + where F: FnOnce(&mut Encoder) -> Result<(), Error> { f(self) } @@ -492,17 +504,17 @@ impl serialize::Decoder for Decoder { } // Compound types: - fn read_enum(&mut self, _name: &str, - f: |&mut Decoder| -> Result) + fn read_enum(&mut self, _name: &str, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { f(self) } - fn read_enum_variant(&mut self, - names: &[&str], - f: |&mut Decoder, uint| -> Result) - -> Result { + fn read_enum_variant(&mut self, names: &[&str], mut f: F) + -> Result + where F: FnMut(&mut Decoder, uint) -> Result + { let mut first_error = None; for i in range(0, names.len()) { let mut d = self.sub_decoder(self.toml.clone(), ""); @@ -517,34 +529,32 @@ impl serialize::Decoder for Decoder { } Err(first_error.unwrap_or_else(|| self.err(NoEnumVariants))) } - fn read_enum_variant_arg(&mut self, - _a_idx: uint, - f: |&mut Decoder| -> Result) - -> Result { + fn read_enum_variant_arg(&mut self, _a_idx: uint, f: F) + -> Result + where F: FnOnce(&mut Decoder) -> Result + { f(self) } - fn read_enum_struct_variant(&mut self, - _names: &[&str], - _f: |&mut Decoder, uint| - -> Result) + fn read_enum_struct_variant(&mut self, _names: &[&str], _f: F) -> Result + where F: FnMut(&mut Decoder, uint) -> Result { panic!() } - fn read_enum_struct_variant_field(&mut self, - _f_name: &str, - _f_idx: uint, - _f: |&mut Decoder| - -> Result) + fn read_enum_struct_variant_field(&mut self, + _f_name: &str, + _f_idx: uint, + _f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { panic!() } - fn read_struct(&mut self, _s_name: &str, _len: uint, - f: |&mut Decoder| -> Result) + fn read_struct(&mut self, _s_name: &str, _len: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { match self.toml { Some(Table(..)) => { @@ -559,11 +569,10 @@ impl serialize::Decoder for Decoder { ref found => Err(self.mismatch("table", found)), } } - fn read_struct_field(&mut self, - f_name: &str, - _f_idx: uint, - f: |&mut Decoder| -> Result) - -> Result { + fn read_struct_field(&mut self, f_name: &str, _f_idx: uint, f: F) + -> Result + where F: FnOnce(&mut Decoder) -> Result + { let field = f_name.to_string(); let toml = match self.toml { Some(Table(ref mut table)) => { @@ -584,45 +593,41 @@ impl serialize::Decoder for Decoder { Ok(ret) } - fn read_tuple(&mut self, - tuple_len: uint, - f: |&mut Decoder| -> Result) + fn read_tuple(&mut self, tuple_len: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { - self.read_seq(|d, len| { + self.read_seq(move |d, len| { assert!(len == tuple_len, "expected tuple of length `{}`, found tuple \ of length `{}`", tuple_len, len); f(d) }) } - fn read_tuple_arg(&mut self, a_idx: uint, - f: |&mut Decoder| -> Result) + fn read_tuple_arg(&mut self, a_idx: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { self.read_seq_elt(a_idx, f) } - fn read_tuple_struct(&mut self, - _s_name: &str, - _len: uint, - _f: |&mut Decoder| -> Result) + fn read_tuple_struct(&mut self, _s_name: &str, _len: uint, _f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { panic!() } - fn read_tuple_struct_arg(&mut self, - _a_idx: uint, - _f: |&mut Decoder| -> Result) + fn read_tuple_struct_arg(&mut self, _a_idx: uint, _f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { panic!() } // Specialized types: - fn read_option(&mut self, - f: |&mut Decoder, bool| -> Result) + fn read_option(&mut self, mut f: F) -> Result + where F: FnMut(&mut Decoder, bool) -> Result { match self.toml { Some(..) => f(self, true), @@ -630,8 +635,9 @@ impl serialize::Decoder for Decoder { } } - fn read_seq(&mut self, f: |&mut Decoder, uint| -> Result) + fn read_seq(&mut self, f: F) -> Result + where F: FnOnce(&mut Decoder,uint) -> Result { let len = match self.toml { Some(Array(ref arr)) => arr.len(), @@ -649,9 +655,9 @@ impl serialize::Decoder for Decoder { self.toml.take(); Ok(ret) } - fn read_seq_elt(&mut self, idx: uint, - f: |&mut Decoder| -> Result) + fn read_seq_elt(&mut self, idx: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { let toml = match self.toml { Some(Array(ref mut arr)) => mem::replace(&mut arr[idx], Integer(0)), @@ -669,8 +675,9 @@ impl serialize::Decoder for Decoder { Ok(ret) } - fn read_map(&mut self, f: |&mut Decoder, uint| -> Result) + fn read_map(&mut self, f: F) -> Result + where F: FnOnce(&mut Decoder, uint) -> Result { let len = match self.toml { Some(Table(ref table)) => table.len(), @@ -680,9 +687,9 @@ impl serialize::Decoder for Decoder { self.toml.take(); Ok(ret) } - fn read_map_elt_key(&mut self, idx: uint, - f: |&mut Decoder| -> Result) + fn read_map_elt_key(&mut self, idx: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { match self.toml { Some(Table(ref table)) => { @@ -697,9 +704,9 @@ impl serialize::Decoder for Decoder { ref found => Err(self.mismatch("table", found)), } } - fn read_map_elt_val(&mut self, idx: uint, - f: |&mut Decoder| -> Result) + fn read_map_elt_val(&mut self, idx: uint, f: F) -> Result + where F: FnOnce(&mut Decoder) -> Result { match self.toml { Some(Table(ref table)) => { -- cgit v1.2.3