From bbfe6b1232f2e821c3000dc31eb94495a329e0ba Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 15 Dec 2021 18:40:18 +0900 Subject: libbinder_rs: PartialEq for ParcelFileDescriptor NDK's ScopedFileDescriptor can be checked for equality. Add impl for PartialEq for ParcelFileDescriptor. With this, @RustDerive(PartialEq=true) works when the parcelable has a ParcelFileDescriptor field. Bug: n/a Test: aidl_integration_test Change-Id: I94d064db46f3e1bf43180e4fee9cf2a0487980e7 --- libs/binder/rust/src/parcel/file_descriptor.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/binder/rust/src/parcel/file_descriptor.rs b/libs/binder/rust/src/parcel/file_descriptor.rs index b0dea945e0..4d3d59afb0 100644 --- a/libs/binder/rust/src/parcel/file_descriptor.rs +++ b/libs/binder/rust/src/parcel/file_descriptor.rs @@ -60,6 +60,16 @@ impl IntoRawFd for ParcelFileDescriptor { } } +impl PartialEq for ParcelFileDescriptor { + // Since ParcelFileDescriptors own the FD, if this function ever returns true (and it is used to + // compare two different objects), then it would imply that an FD is double-owned. + fn eq(&self, other: &Self) -> bool { + self.as_raw_fd() == other.as_raw_fd() + } +} + +impl Eq for ParcelFileDescriptor {} + impl Serialize for ParcelFileDescriptor { fn serialize(&self, parcel: &mut BorrowedParcel<'_>) -> Result<()> { let fd = self.0.as_raw_fd(); -- cgit v1.2.3-59-g8ed1b