Updates for zerocopy 0.8. Bug: 372549215 Test: atest libfmq_rust_unit_test Change-Id: I83bfccbc07493e73eefa6b7ce1ab4bd6e75eaee3
diff --git a/Android.bp b/Android.bp index 8d6e281..8b3a6e1 100644 --- a/Android.bp +++ b/Android.bp
@@ -196,7 +196,7 @@ rustlibs: [ "libfmq_bindgen", "liblog_rust", - "libzerocopy-0.7.35", + "libzerocopy", ], proc_macros: [], }
diff --git a/libfmq.rs b/libfmq.rs index 47c5c15..55a3419 100644 --- a/libfmq.rs +++ b/libfmq.rs
@@ -22,11 +22,11 @@ ndk_ScopedFileDescriptor, ErasedMessageQueue, ErasedMessageQueueDesc, GrantorDescriptor, MQDescriptor, MemTransaction, NativeHandle, ParcelFileDescriptor, SynchronizedReadWrite, }; +use log::error; +use zerocopy::{FromBytes, Immutable, IntoBytes}; use std::ptr::addr_of_mut; -use log::error; - /// A trait indicating that a type is safe to pass through shared memory. /// /// # Safety @@ -40,8 +40,10 @@ /// the same process. As such, `Share` is a supertrait of `Sync`. pub unsafe trait Share: Sync {} -// SAFETY: All types implementing the `zerocopy::AsBytes` trait implement `Share`. -unsafe impl<T: zerocopy::AsBytes + zerocopy::FromBytes + Send + Sync> Share for T {} +// SAFETY: All types implementing the zerocopy `Immutable`, `IntoBytes` and `FromBytes` traits +// implement `Share`, because that implies that they don't have any interior mutability and can be +// treated as just a slice of bytes. +unsafe impl<T: Immutable + IntoBytes + FromBytes + Send + Sync> Share for T {} /// An IPC message queue for values of type T. pub struct MessageQueue<T> {