Skip to content

Commit 5c7ac92

Browse files
committed
Implement RefEncode for *const c_void and *mut c_void
Allows `*const *const c_void` and such.
1 parent cbbd4c5 commit 5c7ac92

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

objc2_encode/src/encode.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,20 @@ unsafe impl Encode for *const c_void {
270270
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
271271
}
272272

273+
unsafe impl RefEncode for *const c_void {
274+
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
275+
}
276+
273277
/// [`Encode`] is implemented manually for `*mut c_void`, instead of
274278
/// implementing [`RefEncode`], to discourage creating `&mut c_void`.
275279
unsafe impl Encode for *mut c_void {
276280
const ENCODING: Encoding<'static> = Encoding::Pointer(&Encoding::Void);
277281
}
278282

283+
unsafe impl RefEncode for *mut c_void {
284+
const ENCODING_REF: Encoding<'static> = Encoding::Pointer(&Self::ENCODING);
285+
}
286+
279287
unsafe impl<T: Encode, const LENGTH: usize> Encode for [T; LENGTH] {
280288
const ENCODING: Encoding<'static> = Encoding::Array(LENGTH, &T::ENCODING);
281289
}
@@ -504,6 +512,10 @@ mod tests {
504512
<*const c_void>::ENCODING,
505513
Encoding::Pointer(&Encoding::Void)
506514
);
515+
assert_eq!(
516+
<&*const c_void>::ENCODING,
517+
Encoding::Pointer(&Encoding::Pointer(&Encoding::Void))
518+
);
507519

508520
// Shouldn't compile
509521
// assert_eq!(<c_void>::ENCODING, Encoding::Void);

0 commit comments

Comments
 (0)