serialize: Change some FnOnce bounds to FnMut

Relax some of the bounds on the decoder methods back to FnMut to help accomodate
some more flavorful variants of decoders which may need to run the closure more
than once when it, for example, attempts to find the first successful enum to
decode.

This a breaking change due to the bounds for the trait switching, and clients
will need to update from `FnOnce` to `FnMut` as well as likely making the local
function binding mutable in order to call the function.

[breaking-change]
This commit is contained in:
Alex Crichton 2014-12-15 09:06:06 -08:00
parent ef0bc464af
commit c9ea7c9a58
3 changed files with 17 additions and 14 deletions

View File

@ -499,8 +499,9 @@ pub mod reader {
Ok(result) Ok(result)
} }
fn read_enum_variant<T, F>(&mut self, _: &[&str], f: F) -> DecodeResult<T> where fn read_enum_variant<T, F>(&mut self, _: &[&str],
F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult<T>, mut f: F) -> DecodeResult<T>
where F: FnMut(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
{ {
debug!("read_enum_variant()"); debug!("read_enum_variant()");
let idx = try!(self._next_uint(EsEnumVid)); let idx = try!(self._next_uint(EsEnumVid));
@ -526,8 +527,9 @@ pub mod reader {
f(self) f(self)
} }
fn read_enum_struct_variant<T, F>(&mut self, _: &[&str], f: F) -> DecodeResult<T> where fn read_enum_struct_variant<T, F>(&mut self, _: &[&str],
F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult<T>, mut f: F) -> DecodeResult<T>
where F: FnMut(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
{ {
debug!("read_enum_struct_variant()"); debug!("read_enum_struct_variant()");
let idx = try!(self._next_uint(EsEnumVid)); let idx = try!(self._next_uint(EsEnumVid));
@ -610,8 +612,8 @@ pub mod reader {
self.read_tuple_arg(idx, f) self.read_tuple_arg(idx, f)
} }
fn read_option<T, F>(&mut self, f: F) -> DecodeResult<T> where fn read_option<T, F>(&mut self, mut f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder<'doc>, bool) -> DecodeResult<T>, F: FnMut(&mut Decoder<'doc>, bool) -> DecodeResult<T>,
{ {
debug!("read_option()"); debug!("read_option()");
self.read_enum("Option", move |this| { self.read_enum("Option", move |this| {

View File

@ -2082,8 +2082,9 @@ impl ::Decoder<DecoderError> for Decoder {
f(self) f(self)
} }
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F) -> DecodeResult<T> where fn read_enum_variant<T, F>(&mut self, names: &[&str],
F: FnOnce(&mut Decoder, uint) -> DecodeResult<T>, mut f: F) -> DecodeResult<T>
where F: FnMut(&mut Decoder, uint) -> DecodeResult<T>,
{ {
debug!("read_enum_variant(names={})", names); debug!("read_enum_variant(names={})", names);
let name = match self.pop() { let name = match self.pop() {
@ -2133,7 +2134,7 @@ impl ::Decoder<DecoderError> for Decoder {
} }
fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> DecodeResult<T> where fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder, uint) -> DecodeResult<T>, F: FnMut(&mut Decoder, uint) -> DecodeResult<T>,
{ {
debug!("read_enum_struct_variant(names={})", names); debug!("read_enum_struct_variant(names={})", names);
self.read_enum_variant(names, f) self.read_enum_variant(names, f)
@ -2230,8 +2231,8 @@ impl ::Decoder<DecoderError> for Decoder {
self.read_tuple_arg(idx, f) self.read_tuple_arg(idx, f)
} }
fn read_option<T, F>(&mut self, f: F) -> DecodeResult<T> where fn read_option<T, F>(&mut self, mut f: F) -> DecodeResult<T> where
F: FnOnce(&mut Decoder, bool) -> DecodeResult<T>, F: FnMut(&mut Decoder, bool) -> DecodeResult<T>,
{ {
debug!("read_option()"); debug!("read_option()");
match self.pop() { match self.pop() {

View File

@ -120,12 +120,12 @@ pub trait Decoder<E> {
F: FnOnce(&mut Self) -> Result<T, E>; F: FnOnce(&mut Self) -> Result<T, E>;
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where
F: FnOnce(&mut Self, uint) -> Result<T, E>; F: FnMut(&mut Self, uint) -> Result<T, E>;
fn read_enum_variant_arg<T, F>(&mut self, a_idx: uint, f: F) -> Result<T, E> where fn read_enum_variant_arg<T, F>(&mut self, a_idx: uint, f: F) -> Result<T, E> where
F: FnOnce(&mut Self) -> Result<T, E>; F: FnOnce(&mut Self) -> Result<T, E>;
fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where
F: FnOnce(&mut Self, uint) -> Result<T, E>; F: FnMut(&mut Self, uint) -> Result<T, E>;
fn read_enum_struct_variant_field<T, F>(&mut self, fn read_enum_struct_variant_field<T, F>(&mut self,
&f_name: &str, &f_name: &str,
f_idx: uint, f_idx: uint,
@ -154,7 +154,7 @@ pub trait Decoder<E> {
// Specialized types: // Specialized types:
fn read_option<T, F>(&mut self, f: F) -> Result<T, E> where fn read_option<T, F>(&mut self, f: F) -> Result<T, E> where
F: FnOnce(&mut Self, bool) -> Result<T, E>; F: FnMut(&mut Self, bool) -> Result<T, E>;
fn read_seq<T, F>(&mut self, f: F) -> Result<T, E> where fn read_seq<T, F>(&mut self, f: F) -> Result<T, E> where
F: FnOnce(&mut Self, uint) -> Result<T, E>; F: FnOnce(&mut Self, uint) -> Result<T, E>;