@@ -588,7 +588,7 @@ impl<T: Trace + ?Sized> GcCell<T> {
588
588
}
589
589
590
590
Ok ( GcCellRefMut {
591
- flags : & self . flags ,
591
+ gc_cell : self ,
592
592
value : & mut * self . cell . get ( ) ,
593
593
} )
594
594
}
@@ -795,12 +795,12 @@ impl<'a, T: ?Sized + Display> Display for GcCellRef<'a, T> {
795
795
}
796
796
797
797
/// A wrapper type for a mutably borrowed value from a `GcCell<T>`.
798
- pub struct GcCellRefMut < ' a , T : Trace + ?Sized + ' static > {
799
- flags : & ' a Cell < BorrowFlag > ,
800
- value : & ' a mut T ,
798
+ pub struct GcCellRefMut < ' a , T : Trace + ?Sized + ' static , U : ? Sized = T > {
799
+ gc_cell : & ' a GcCell < T > ,
800
+ value : & ' a mut U ,
801
801
}
802
802
803
- impl < ' a , T : Trace + ?Sized > GcCellRefMut < ' a , T > {
803
+ impl < ' a , T : Trace + ?Sized , U : ? Sized > GcCellRefMut < ' a , T , U > {
804
804
/// Makes a new `GcCellRefMut` for a component of the borrowed data, e.g., an enum
805
805
/// variant.
806
806
///
@@ -818,22 +818,22 @@ impl<'a, T: Trace + ?Sized> GcCellRefMut<'a, T> {
818
818
/// let c = GcCell::new((5, 'b'));
819
819
/// {
820
820
/// let b1: GcCellRefMut<(u32, char)> = c.borrow_mut();
821
- /// let mut b2: GcCellRefMut<u32> = GcCellRefMut::map(b1, |t| &mut t.0);
821
+ /// let mut b2: GcCellRefMut<(u32, char), u32> = GcCellRefMut::map(b1, |t| &mut t.0);
822
822
/// assert_eq!(*b2, 5);
823
823
/// *b2 = 42;
824
824
/// }
825
825
/// assert_eq!(*c.borrow(), (42, 'b'));
826
826
/// ```
827
827
#[ inline]
828
- pub fn map < U , F > ( orig : Self , f : F ) -> GcCellRefMut < ' a , U >
828
+ pub fn map < V , F > ( orig : Self , f : F ) -> GcCellRefMut < ' a , T , V >
829
829
where
830
- U : Trace + ?Sized ,
831
- F : FnOnce ( & mut T ) -> & mut U ,
830
+ V : ?Sized ,
831
+ F : FnOnce ( & mut U ) -> & mut V ,
832
832
{
833
- let value = unsafe { & mut * ( orig. value as * mut T ) } ;
833
+ let value = unsafe { & mut * ( orig. value as * mut U ) } ;
834
834
835
835
let ret = GcCellRefMut {
836
- flags : orig. flags ,
836
+ gc_cell : orig. gc_cell ,
837
837
value : f ( value) ,
838
838
} ;
839
839
@@ -845,44 +845,44 @@ impl<'a, T: Trace + ?Sized> GcCellRefMut<'a, T> {
845
845
}
846
846
}
847
847
848
- impl < ' a , T : Trace + ?Sized > Deref for GcCellRefMut < ' a , T > {
849
- type Target = T ;
848
+ impl < ' a , T : Trace + ?Sized , U : ? Sized > Deref for GcCellRefMut < ' a , T , U > {
849
+ type Target = U ;
850
850
851
851
#[ inline]
852
- fn deref ( & self ) -> & T {
852
+ fn deref ( & self ) -> & U {
853
853
self . value
854
854
}
855
855
}
856
856
857
- impl < ' a , T : Trace + ?Sized > DerefMut for GcCellRefMut < ' a , T > {
857
+ impl < ' a , T : Trace + ?Sized , U : ? Sized > DerefMut for GcCellRefMut < ' a , T , U > {
858
858
#[ inline]
859
- fn deref_mut ( & mut self ) -> & mut T {
859
+ fn deref_mut ( & mut self ) -> & mut U {
860
860
self . value
861
861
}
862
862
}
863
863
864
- impl < ' a , T : Trace + ?Sized > Drop for GcCellRefMut < ' a , T > {
864
+ impl < ' a , T : Trace + ?Sized , U : ? Sized > Drop for GcCellRefMut < ' a , T , U > {
865
865
#[ inline]
866
866
fn drop ( & mut self ) {
867
- debug_assert ! ( self . flags. get( ) . borrowed( ) == BorrowState :: Writing ) ;
867
+ debug_assert ! ( self . gc_cell . flags. get( ) . borrowed( ) == BorrowState :: Writing ) ;
868
868
// Restore the rooted state of the GcCell's contents to the state of the GcCell.
869
869
// During the lifetime of the GcCellRefMut, the GcCell's contents are rooted.
870
- if !self . flags . get ( ) . rooted ( ) {
870
+ if !self . gc_cell . flags . get ( ) . rooted ( ) {
871
871
unsafe {
872
- self . value . unroot ( ) ;
872
+ ( * self . gc_cell . cell . get ( ) ) . unroot ( ) ;
873
873
}
874
874
}
875
- self . flags . set ( self . flags . get ( ) . set_unused ( ) ) ;
875
+ self . gc_cell . flags . set ( self . gc_cell . flags . get ( ) . set_unused ( ) ) ;
876
876
}
877
877
}
878
878
879
- impl < ' a , T : Trace + ?Sized + Debug > Debug for GcCellRefMut < ' a , T > {
879
+ impl < ' a , T : Trace + ?Sized , U : Debug + ? Sized > Debug for GcCellRefMut < ' a , T , U > {
880
880
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
881
881
Debug :: fmt ( & * ( self . deref ( ) ) , f)
882
882
}
883
883
}
884
884
885
- impl < ' a , T : Trace + ?Sized + Display > Display for GcCellRefMut < ' a , T > {
885
+ impl < ' a , T : Trace + ?Sized , U : Display + ? Sized > Display for GcCellRefMut < ' a , T , U > {
886
886
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
887
887
Display :: fmt ( & * * self , f)
888
888
}
0 commit comments