From 807c5e8c8d9a6275846e010007119ba64f42f105 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 6 Dec 2014 16:53:18 -0500 Subject: [PATCH] librbml: fix fallout --- src/librbml/lib.rs | 257 +++++++++++++++++++++++---------------------- 1 file changed, 133 insertions(+), 124 deletions(-) diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 426a987d25d..ef59b4742fa 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -25,6 +25,7 @@ html_playground_url = "http://play.rust-lang.org/")] #![allow(unknown_features)] #![feature(macro_rules, phase, slicing_syntax, globs)] +#![feature(unboxed_closures)] #![allow(missing_docs)] extern crate serialize; @@ -378,8 +379,9 @@ pub mod reader { Ok(r_doc) } - fn push_doc(&mut self, exp_tag: EbmlEncoderTag, - f: |&mut Decoder<'doc>| -> DecodeResult) -> DecodeResult { + fn push_doc(&mut self, exp_tag: EbmlEncoderTag, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { let d = try!(self.next_doc(exp_tag)); let old_parent = self.parent; let old_pos = self.pos; @@ -471,9 +473,9 @@ pub mod reader { } // Compound types: - fn read_enum(&mut self, - name: &str, - f: |&mut Decoder<'doc>| -> DecodeResult) -> DecodeResult { + fn read_enum(&mut self, name: &str, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_enum({})", name); try!(self._check_label(name)); @@ -490,10 +492,9 @@ pub mod reader { Ok(result) } - fn read_enum_variant(&mut self, - _: &[&str], - f: |&mut Decoder<'doc>, uint| -> DecodeResult) - -> DecodeResult { + fn read_enum_variant(&mut self, _: &[&str], f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult, + { debug!("read_enum_variant()"); let idx = try!(self._next_uint(EsEnumVid)); debug!(" idx={}", idx); @@ -511,17 +512,16 @@ pub mod reader { Ok(result) } - fn read_enum_variant_arg(&mut self, - idx: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) -> DecodeResult { + fn read_enum_variant_arg(&mut self, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_enum_variant_arg(idx={})", idx); f(self) } - fn read_enum_struct_variant(&mut self, - _: &[&str], - f: |&mut Decoder<'doc>, uint| -> DecodeResult) - -> DecodeResult { + fn read_enum_struct_variant(&mut self, _: &[&str], f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult, + { debug!("read_enum_struct_variant()"); let idx = try!(self._next_uint(EsEnumVid)); debug!(" idx={}", idx); @@ -539,39 +539,37 @@ pub mod reader { Ok(result) } - fn read_enum_struct_variant_field(&mut self, - name: &str, - idx: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { - debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx); + fn read_enum_struct_variant_field(&mut self, + name: &str, + idx: uint, + f: F) + -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { + debug!("read_enum_struct_variant_arg(name={}, idx={})", name, idx); f(self) } - fn read_struct(&mut self, - name: &str, - _: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_struct(&mut self, name: &str, _: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_struct(name={})", name); f(self) } - fn read_struct_field(&mut self, - name: &str, - idx: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_struct_field(&mut self, name: &str, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_struct_field(name={}, idx={})", name, idx); try!(self._check_label(name)); f(self) } - fn read_tuple(&mut self, - tuple_len: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) -> DecodeResult { + fn read_tuple(&mut self, tuple_len: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_tuple()"); - self.read_seq(|d, len| { + self.read_seq(move |d, len| { if len == tuple_len { f(d) } else { @@ -581,34 +579,36 @@ pub mod reader { }) } - fn read_tuple_arg(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_tuple_arg(&mut self, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_tuple_arg(idx={})", idx); self.read_seq_elt(idx, f) } - fn read_tuple_struct(&mut self, - name: &str, - len: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_tuple_struct(&mut self, name: &str, len: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_tuple_struct(name={})", name); self.read_tuple(len, f) } - fn read_tuple_struct_arg(&mut self, - idx: uint, - f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_tuple_struct_arg(&mut self, + idx: uint, + f: F) + -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_tuple_struct_arg(idx={})", idx); self.read_tuple_arg(idx, f) } - fn read_option(&mut self, - f: |&mut Decoder<'doc>, bool| -> DecodeResult) -> DecodeResult { + fn read_option(&mut self, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>, bool) -> DecodeResult, + { debug!("read_option()"); - self.read_enum("Option", |this| { - this.read_enum_variant(&["None", "Some"], |this, idx| { + self.read_enum("Option", move |this| { + this.read_enum_variant(&["None", "Some"], move |this, idx| { match idx { 0 => f(this, false), 1 => f(this, true), @@ -620,40 +620,45 @@ pub mod reader { }) } - fn read_seq(&mut self, - f: |&mut Decoder<'doc>, uint| -> DecodeResult) -> DecodeResult { + fn read_seq(&mut self, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult, + { debug!("read_seq()"); - self.push_doc(EsVec, |d| { + self.push_doc(EsVec, move |d| { let len = try!(d._next_uint(EsVecLen)); debug!(" len={}", len); f(d, len) }) } - fn read_seq_elt(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_seq_elt(&mut self, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_seq_elt(idx={})", idx); self.push_doc(EsVecElt, f) } - fn read_map(&mut self, - f: |&mut Decoder<'doc>, uint| -> DecodeResult) -> DecodeResult { + fn read_map(&mut self, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult, + { debug!("read_map()"); - self.push_doc(EsMap, |d| { + self.push_doc(EsMap, move |d| { let len = try!(d._next_uint(EsMapLen)); debug!(" len={}", len); f(d, len) }) } - fn read_map_elt_key(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_map_elt_key(&mut self, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_map_elt_key(idx={})", idx); self.push_doc(EsMapKey, f) } - fn read_map_elt_val(&mut self, idx: uint, f: |&mut Decoder<'doc>| -> DecodeResult) - -> DecodeResult { + fn read_map_elt_val(&mut self, idx: uint, f: F) -> DecodeResult where + F: FnOnce(&mut Decoder<'doc>) -> DecodeResult, + { debug!("read_map_elt_val(idx={})", idx); self.push_doc(EsMapVal, f) } @@ -916,102 +921,106 @@ pub mod writer { self.wr_tagged_str(EsStr as uint, v) } - fn emit_enum(&mut self, - name: &str, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_enum(&mut self, name: &str, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self._emit_label(name)); try!(self.start_tag(EsEnum as uint)); try!(f(self)); self.end_tag() } - fn emit_enum_variant(&mut self, - _: &str, - v_id: uint, - _: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_enum_variant(&mut self, + _: &str, + v_id: uint, + _: uint, + f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self._emit_tagged_uint(EsEnumVid, v_id)); try!(self.start_tag(EsEnumBody as uint)); try!(f(self)); self.end_tag() } - fn emit_enum_variant_arg(&mut self, - _: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_enum_variant_arg(&mut self, _: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { f(self) } - fn emit_enum_struct_variant(&mut self, - v_name: &str, - v_id: uint, - cnt: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_enum_struct_variant(&mut self, + v_name: &str, + v_id: uint, + cnt: uint, + f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_enum_variant(v_name, v_id, cnt, f) } - fn emit_enum_struct_variant_field(&mut self, - _: &str, - idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) - -> EncodeResult { + fn emit_enum_struct_variant_field(&mut self, + _: &str, + idx: uint, + f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_enum_variant_arg(idx, f) } - fn emit_struct(&mut self, - _: &str, - _len: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_struct(&mut self, _: &str, _len: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { f(self) } - fn emit_struct_field(&mut self, - name: &str, - _: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_struct_field(&mut self, name: &str, _: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self._emit_label(name)); f(self) } - fn emit_tuple(&mut self, - len: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_tuple(&mut self, len: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_seq(len, f) } - fn emit_tuple_arg(&mut self, - idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_tuple_arg(&mut self, idx: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_seq_elt(idx, f) } - fn emit_tuple_struct(&mut self, - _: &str, - len: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_tuple_struct(&mut self, _: &str, len: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_seq(len, f) } - fn emit_tuple_struct_arg(&mut self, - idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_tuple_struct_arg(&mut self, idx: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_seq_elt(idx, f) } - fn emit_option(&mut self, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_option(&mut self, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_enum("Option", f) } fn emit_option_none(&mut self) -> EncodeResult { self.emit_enum_variant("None", 0, 0, |_| Ok(())) } - fn emit_option_some(&mut self, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_option_some(&mut self, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { self.emit_enum_variant("Some", 1, 1, f) } - fn emit_seq(&mut self, - len: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_seq(&mut self, len: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self.start_tag(EsVec as uint)); try!(self._emit_tagged_uint(EsVecLen, len)); @@ -1019,18 +1028,18 @@ pub mod writer { self.end_tag() } - fn emit_seq_elt(&mut self, - _idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_seq_elt(&mut self, _idx: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self.start_tag(EsVecElt as uint)); try!(f(self)); self.end_tag() } - fn emit_map(&mut self, - len: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_map(&mut self, len: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self.start_tag(EsMap as uint)); try!(self._emit_tagged_uint(EsMapLen, len)); @@ -1038,18 +1047,18 @@ pub mod writer { self.end_tag() } - fn emit_map_elt_key(&mut self, - _idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_map_elt_key(&mut self, _idx: uint, mut f: F) -> EncodeResult where + F: FnMut(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self.start_tag(EsMapKey as uint)); try!(f(self)); self.end_tag() } - fn emit_map_elt_val(&mut self, - _idx: uint, - f: |&mut Encoder<'a, W>| -> EncodeResult) -> EncodeResult { + fn emit_map_elt_val(&mut self, _idx: uint, f: F) -> EncodeResult where + F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult, + { try!(self.start_tag(EsMapVal as uint)); try!(f(self)); self.end_tag()