File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ impl<T> Cell<T> {
50
50
this. value . take_unwrap ( )
51
51
}
52
52
53
+ /// Yields the value if the cell is full, or `None` if it is empty.
54
+ pub fn take_opt ( & self ) -> Option < T > {
55
+ let this = unsafe { transmute_mut ( self ) } ;
56
+ this. value . take ( )
57
+ }
58
+
53
59
/// Returns the value, failing if the cell is full.
54
60
pub fn put_back ( & self , value : T ) {
55
61
let this = unsafe { transmute_mut ( self ) } ;
Original file line number Diff line number Diff line change @@ -499,13 +499,14 @@ impl<T> GenericPort<T> for Port<T> {
499
499
}
500
500
501
501
fn try_recv ( & self ) -> Option < T > {
502
- let pone = self . next . take ( ) ;
503
- match pone. try_recv ( ) {
504
- Some ( StreamPayload { val, next } ) => {
505
- self . next . put_back ( next) ;
506
- Some ( val)
502
+ do self . next . take_opt ( ) . map_move_default ( None ) |pone| {
503
+ match pone. try_recv ( ) {
504
+ Some ( StreamPayload { val, next } ) => {
505
+ self . next . put_back ( next) ;
506
+ Some ( val)
507
+ }
508
+ None => None
507
509
}
508
- None => None
509
510
}
510
511
}
511
512
}
You can’t perform that action at this time.
0 commit comments