File tree 3 files changed +17
-11
lines changed
3 files changed +17
-11
lines changed Original file line number Diff line number Diff line change @@ -411,13 +411,13 @@ pub mod reader {
411
411
}
412
412
413
413
#[cfg(stage0)]
414
- fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
414
+ fn read_option<T>(&self, f: &fn(bool ) -> T) -> T {
415
415
debug!(" read_option( ) ");
416
416
do self.read_enum(" Option ") || {
417
417
do self.read_enum_variant |idx| {
418
418
match idx {
419
- 0 => None ,
420
- 1 => Some(f() ),
419
+ 0 => f(false) ,
420
+ 1 => f(true ),
421
421
_ => fail!(),
422
422
}
423
423
}
@@ -427,13 +427,13 @@ pub mod reader {
427
427
#[cfg(stage1)]
428
428
#[cfg(stage2)]
429
429
#[cfg(stage3)]
430
- fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
430
+ fn read_option<T>(&self, f: &fn(bool ) -> T) -> T {
431
431
debug!(" read_option( ) ");
432
432
do self.read_enum(" Option ") || {
433
433
do self.read_enum_variant([" None ", " Some "]) |idx| {
434
434
match idx {
435
- 0 => None ,
436
- 1 => Some(f() ),
435
+ 0 => f(false) ,
436
+ 1 => f(true ),
437
437
_ => fail!(),
438
438
}
439
439
}
Original file line number Diff line number Diff line change @@ -980,10 +980,10 @@ impl<'self> serialize::Decoder for Decoder<'self> {
980
980
}
981
981
}
982
982
983
- fn read_option<T>(&self, f: &fn() -> T) -> Option<T> {
983
+ fn read_option<T>(&self, f: &fn(bool ) -> T) -> T {
984
984
match *self.peek() {
985
- Null => { self.pop(); None }
986
- _ => Some(f() ),
985
+ Null => { self.pop(); f(false) }
986
+ _ => f(true ),
987
987
}
988
988
}
989
989
}
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ pub trait Decoder {
118
118
fn read_tup_elt < T > ( & self , idx : uint , f : & fn ( ) -> T ) -> T ;
119
119
120
120
// Specialized types:
121
- fn read_option < T > ( & self , f : & fn ( ) -> T ) -> Option < T > ;
121
+ fn read_option < T > ( & self , f : & fn ( bool ) -> T ) -> T ;
122
122
}
123
123
124
124
pub trait Encodable < S : Encoder > {
@@ -395,7 +395,13 @@ impl<S:Encoder,T:Encodable<S>> Encodable<S> for Option<T> {
395
395
396
396
impl < D : Decoder , T : Decodable < D > > Decodable < D > for Option < T > {
397
397
fn decode ( d : & D ) -> Option < T > {
398
- d. read_option ( || Decodable :: decode ( d) )
398
+ do d. read_option |b| {
399
+ if b {
400
+ Some ( Decodable :: decode ( d) )
401
+ } else {
402
+ None
403
+ }
404
+ }
399
405
}
400
406
}
401
407
You can’t perform that action at this time.
0 commit comments