1- use crate :: { storage:: StorageItem , Epoch , Index } ;
2- use alloc:: sync:: Arc ;
1+ use crate :: { Epoch , Index } ;
32use core:: {
43 cmp:: Ordering ,
54 fmt:: { self , Debug } ,
@@ -96,21 +95,25 @@ pub enum SerialId {
9695 Id ( Index , Epoch ) ,
9796}
9897
98+ #[ cfg( feature = "serde" ) ]
9999impl From < RawId > for SerialId {
100100 fn from ( id : RawId ) -> Self {
101101 let ( index, epoch) = id. unzip ( ) ;
102102 Self :: Id ( index, epoch)
103103 }
104104}
105105
106+ #[ cfg( feature = "serde" ) ]
106107pub struct ZeroIdError ;
107108
109+ #[ cfg( feature = "serde" ) ]
108110impl fmt:: Display for ZeroIdError {
109111 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
110112 write ! ( f, "IDs may not be zero" )
111113 }
112114}
113115
116+ #[ cfg( feature = "serde" ) ]
114117impl TryFrom < SerialId > for RawId {
115118 type Error = ZeroIdError ;
116119 fn try_from ( id : SerialId ) -> Result < Self , ZeroIdError > {
@@ -127,21 +130,24 @@ impl TryFrom<SerialId> for RawId {
127130///
128131/// This is used for tracing.
129132#[ allow( dead_code) ]
130- #[ cfg_attr ( feature = "serde" , derive ( serde :: Serialize , serde :: Deserialize ) ) ]
131- #[ derive( Debug ) ]
133+ #[ cfg ( feature = "serde" ) ]
134+ #[ derive( Debug , serde :: Serialize , serde :: Deserialize ) ]
132135pub enum PointerId < T : Marker > {
133136 // The only variant forces RON to not ignore "Id"
134137 PointerId ( usize , #[ serde( skip) ] PhantomData < T > ) ,
135138}
136139
140+ #[ cfg( feature = "serde" ) ]
137141impl < T : Marker > Copy for PointerId < T > { }
138142
143+ #[ cfg( feature = "serde" ) ]
139144impl < T : Marker > Clone for PointerId < T > {
140145 fn clone ( & self ) -> Self {
141146 * self
142147 }
143148}
144149
150+ #[ cfg( feature = "serde" ) ]
145151impl < T : Marker > PartialEq for PointerId < T > {
146152 fn eq ( & self , other : & Self ) -> bool {
147153 let PointerId :: PointerId ( this, _) = self ;
@@ -150,25 +156,28 @@ impl<T: Marker> PartialEq for PointerId<T> {
150156 }
151157}
152158
159+ #[ cfg( feature = "serde" ) ]
153160impl < T : Marker > Eq for PointerId < T > { }
154161
162+ #[ cfg( feature = "serde" ) ]
155163impl < T : Marker > Hash for PointerId < T > {
156164 fn hash < H : core:: hash:: Hasher > ( & self , state : & mut H ) {
157165 let PointerId :: PointerId ( this, _) = self ;
158166 this. hash ( state) ;
159167 }
160168}
161169
162- impl < T : StorageItem > From < & Arc < T > > for PointerId < T :: Marker > {
163- fn from ( arc : & Arc < T > ) -> Self {
170+ #[ cfg( feature = "serde" ) ]
171+ impl < T : crate :: storage:: StorageItem > From < & alloc:: sync:: Arc < T > > for PointerId < T :: Marker > {
172+ fn from ( arc : & alloc:: sync:: Arc < T > ) -> Self {
164173 // Since the memory representation of `Arc<T>` is just a pointer to
165174 // `ArcInner<T>`, it would be nice to use that pointer as the trace ID,
166175 // since many `into_trace` implementations would then be no-ops at
167176 // runtime. However, `Arc::as_ptr` returns a pointer to the contained
168177 // data, not to the `ArcInner`. The `ArcInner` stores the reference
169178 // counts before the data, so the machine code for this conversion has
170179 // to add an offset to the pointer.
171- PointerId :: PointerId ( Arc :: as_ptr ( arc) as usize , PhantomData )
180+ PointerId :: PointerId ( alloc :: sync :: Arc :: as_ptr ( arc) as usize , PhantomData )
172181 }
173182}
174183
0 commit comments