File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -73,3 +73,34 @@ unsafe impl Encode for *const c_void {
73
73
74
74
fn encode ( ) -> Self :: Encoding { Pointer :: new ( Primitive :: Void ) }
75
75
}
76
+
77
+ /*
78
+ External crates cannot implement Encode for pointers or Optionals, but they
79
+ *can* implement it for references. rust-lang/rust#25126
80
+
81
+ As a workaround, we provide implementations for these types that return the
82
+ same encoding as references.
83
+ */
84
+ unsafe impl < T : ' static > Encode for * const T where for < ' a > & ' a T : Encode {
85
+ type Encoding = <& ' static T as Encode >:: Encoding ;
86
+
87
+ fn encode ( ) -> Self :: Encoding { <& T >:: encode ( ) }
88
+ }
89
+
90
+ unsafe impl < T : ' static > Encode for * mut T where for < ' a > & ' a mut T : Encode {
91
+ type Encoding = <& ' static mut T as Encode >:: Encoding ;
92
+
93
+ fn encode ( ) -> Self :: Encoding { <& mut T >:: encode ( ) }
94
+ }
95
+
96
+ unsafe impl < ' a , T > Encode for Option < & ' a T > where & ' a T : Encode {
97
+ type Encoding = <& ' a T as Encode >:: Encoding ;
98
+
99
+ fn encode ( ) -> Self :: Encoding { <& T >:: encode ( ) }
100
+ }
101
+
102
+ unsafe impl < ' a , T > Encode for Option < & ' a mut T > where & ' a mut T : Encode {
103
+ type Encoding = <& ' a mut T as Encode >:: Encoding ;
104
+
105
+ fn encode ( ) -> Self :: Encoding { <& mut T >:: encode ( ) }
106
+ }
You can’t perform that action at this time.
0 commit comments