File tree 1 file changed +10
-7
lines changed
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -101,17 +101,20 @@ macro_rules! define_label {
101
101
102
102
$( #[ $label_attr] ) *
103
103
pub trait $label_name: ' static {
104
- /// Essentially acts like a trait object virtual table,
105
- /// but specialized for labels.
106
- const VTABLE : $crate:: label:: VTable = $crate:: label:: VTable {
107
- ty: || :: std:: any:: TypeId :: of:: <Self >( ) ,
108
- fmt: Self :: fmt,
109
- } ;
110
104
/// Converts this type into an opaque, strongly-typed label.
111
105
#[ inline]
112
106
fn as_label( & self ) -> $id_name {
107
+ // This is just machinery that lets us store the TypeId and formatter fn in the same static reference.
108
+ struct VTables <L : ?:: std:: marker:: Sized >( :: std:: marker:: PhantomData <L >) ;
109
+ impl <L : $label_name + ?:: std:: marker:: Sized > VTables <L > {
110
+ const VTABLE : $crate:: label:: VTable = $crate:: label:: VTable {
111
+ ty: || :: std:: any:: TypeId :: of:: <Self >( ) ,
112
+ fmt: <L as $label_name>:: fmt,
113
+ } ;
114
+ }
115
+
113
116
let data = self . data( ) ;
114
- $id_name { data, vtable: & Self :: VTABLE }
117
+ $id_name { data, vtable: & VTables :: < Self > :: VTABLE }
115
118
}
116
119
/// Returns a number used to distinguish different labels of the same type.
117
120
fn data( & self ) -> u64 ;
You can’t perform that action at this time.
0 commit comments