Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk: Implement common traits where sensible, and drop some Ord #483

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ndk/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
/// A native [`AAssetManager *`]
///
/// [`AAssetManager *`]: https://developer.android.com/ndk/reference/group/asset#aassetmanager
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash)]
#[doc(alias = "AAssetManager")]
pub struct AssetManager {
Comment on lines +17 to 19
Copy link
Member Author

@MarijnS95 MarijnS95 Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be Clone/Copy since this is a cheap reference/handle from Activity (but should carry a lifetime on Activity realistically).

EDIT: Turns out I already started looking into this at https://github.com/rust-mobile/ndk/compare/asset-lifetime

ptr: NonNull<ffi::AAssetManager>,
Expand Down Expand Up @@ -92,7 +92,7 @@ impl AssetManager {
/// ```
///
/// [`AAssetDir *`]: https://developer.android.com/ndk/reference/group/asset#aassetdir
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash)]
#[doc(alias = "AAssetDir")]
pub struct AssetDir {
ptr: NonNull<ffi::AAssetDir>,
Expand Down Expand Up @@ -175,7 +175,7 @@ impl Iterator for AssetDir {
/// ```
///
/// [`AAsset *`]: https://developer.android.com/ndk/reference/group/asset#aasset
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash)]
#[doc(alias = "AAsset")]
pub struct Asset {
ptr: NonNull<ffi::AAsset>,
Expand Down
29 changes: 15 additions & 14 deletions ndk/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::utils::abort_on_panic;
/// [`android.media.AudioAttributes`]: https://developer.android.com/reference/android/media/AudioAttributes
#[cfg(feature = "api-level-29")]
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_allowed_capture_policy_t")]
#[non_exhaustive]
pub enum AudioAllowedCapturePolicy {
Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum AudioAllowedCapturePolicy {
/// [`android.media.AudioAttributes`]: https://developer.android.com/reference/android/media/AudioAttributes
#[cfg(feature = "api-level-28")]
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_content_type_t")]
#[non_exhaustive]
pub enum AudioContentType {
Expand All @@ -107,7 +107,7 @@ pub enum AudioContentType {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_direction_t")]
#[non_exhaustive]
pub enum AudioDirection {
Expand All @@ -124,7 +124,7 @@ pub enum AudioDirection {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[allow(non_camel_case_types)]
#[doc(alias = "aaudio_format_t")]
#[non_exhaustive]
Expand Down Expand Up @@ -159,7 +159,7 @@ pub enum AudioFormat {
/// Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
#[cfg(feature = "api-level-28")]
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_input_preset_t")]
#[non_exhaustive]
pub enum AudioInputPreset {
Expand Down Expand Up @@ -193,7 +193,7 @@ pub enum AudioInputPreset {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_performance_mode_t")]
#[non_exhaustive]
pub enum AudioPerformanceMode {
Expand All @@ -216,7 +216,7 @@ pub enum AudioPerformanceMode {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_sharing_mode_t")]
#[non_exhaustive]
pub enum AudioSharingMode {
Expand Down Expand Up @@ -245,7 +245,7 @@ pub enum AudioSharingMode {
/// [`android.media.AudioAttributes`]: https://developer.android.com/reference/android/media/AudioAttributes
#[cfg(feature = "api-level-28")]
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_usage_t")]
#[non_exhaustive]
pub enum AudioUsage {
Expand Down Expand Up @@ -312,7 +312,7 @@ pub enum AudioUsage {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_stream_state_t")]
#[non_exhaustive]
pub enum AudioStreamState {
Expand Down Expand Up @@ -358,21 +358,21 @@ impl AudioStreamState {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[doc(alias = "aaudio_session_id_t")]
pub enum SessionId {
None,
Allocated(NonZeroI32),
}

#[derive(Copy, Clone, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Timestamp {
pub frame_position: i64,
pub time_nanoseconds: i64,
}

#[repr(u32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Clockid {
#[doc(alias = "CLOCK_MONOTONIC")]
Expand All @@ -383,7 +383,7 @@ pub enum Clockid {

/// Value returned the data callback function.
#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, IntoPrimitive)]
#[doc(alias = "aaudio_data_callback_result_t")]
#[non_exhaustive]
pub enum AudioCallbackResult {
Expand All @@ -399,7 +399,7 @@ pub enum AudioCallbackResult {
}

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "aaudio_result_t")]
#[non_exhaustive]
pub enum AudioError {
Expand Down Expand Up @@ -983,6 +983,7 @@ impl Drop for AudioStreamBuilder {
///
/// [`AAudioStream *`]: https://developer.android.com/ndk/reference/group/audio#aaudiostream
#[doc(alias = "AAudioStream")]
// #[derive(Debug, PartialEq, Eq, Hash)]
pub struct AudioStream {
inner: NonNull<ffi::AAudioStream>,
data_callback: Option<AudioStreamDataCallback>,
Expand Down
14 changes: 7 additions & 7 deletions ndk/src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::data_space::DataSpace;
use crate::hardware_buffer::HardwareBufferRef;

#[repr(i32)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[non_exhaustive]
pub enum BitmapError {
#[doc(alias = "ANDROID_BITMAP_RESULT_ALLOCATION_FAILED")]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub enum BitmapFormat {
/// An immediate wrapper over [`android.graphics.Bitmap`]
///
/// [`android.graphics.Bitmap`]: https://developer.android.com/reference/android/graphics/Bitmap
#[derive(Debug)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct Bitmap {
env: *mut JNIEnv,
inner: jobject,
Expand Down Expand Up @@ -299,7 +299,7 @@ impl Bitmap {
/// Possible values for [`ffi::ANDROID_BITMAP_FLAGS_ALPHA_MASK`] within [`BitmapInfoFlags`]
#[repr(u32)]
#[cfg(feature = "api-level-30")]
#[derive(Clone, Copy, Debug, IntoPrimitive, FromPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "ANDROID_BITMAP_FLAGS_ALPHA_MASK")]
#[non_exhaustive]
pub enum BitmapInfoFlagsAlpha {
Expand All @@ -321,7 +321,7 @@ pub enum BitmapInfoFlagsAlpha {
/// Bitfield containing information about the bitmap.
#[cfg(feature = "api-level-30")]
#[repr(transparent)]
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct BitmapInfoFlags(u32);

#[cfg(feature = "api-level-30")]
Expand Down Expand Up @@ -359,7 +359,7 @@ impl BitmapInfoFlags {
/// A native [`AndroidBitmapInfo`]
///
/// [`AndroidBitmapInfo`]: https://developer.android.com/ndk/reference/struct/android-bitmap-info#struct_android_bitmap_info
#[derive(Clone, Copy)]
#[derive(Clone, Copy)] // TODO: PartialEq, Eq, Hash
#[doc(alias = "AndroidBitmapInfo")]
pub struct BitmapInfo {
inner: ffi::AndroidBitmapInfo,
Expand Down Expand Up @@ -440,7 +440,7 @@ impl BitmapInfo {
/// [`Bitmap::compress_raw()`].
#[cfg(feature = "api-level-30")]
#[repr(i32)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[doc(alias = "AndroidBitmapCompressFormat")]
#[non_exhaustive]
pub enum BitmapCompressFormat {
Expand Down Expand Up @@ -477,7 +477,7 @@ pub enum BitmapCompressFormat {

/// Encapsulates possible errors returned by [`Bitmap::compress()`] or [`Bitmap::compress_raw()`].
#[cfg(feature = "api-level-30")]
#[derive(Debug, thiserror::Error)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, thiserror::Error)]
pub enum BitmapCompressError {
#[error(transparent)]
BitmapError(#[from] BitmapError),
Expand Down
33 changes: 17 additions & 16 deletions ndk/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::ptr::NonNull;
/// [`Configuration`] is an opaque type used to get and set various subsystem configurations.
///
/// [`AConfiguration *`]: https://developer.android.com/ndk/reference/group/configuration#aconfiguration
// TODO: Implement hash based on ptr or contents?
pub struct Configuration {
ptr: NonNull<ffi::AConfiguration>,
}
Expand Down Expand Up @@ -280,7 +281,7 @@ impl Configuration {
}

/// A bitfield representing the differences between two [`Configuration`]s
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct DiffResult(pub u32);

impl DiffResult {
Expand Down Expand Up @@ -337,7 +338,7 @@ impl DiffResult {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum Orientation {
Expand All @@ -351,7 +352,7 @@ pub enum Orientation {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum Touchscreen {
Expand All @@ -365,7 +366,7 @@ pub enum Touchscreen {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)] // TODO: Ord?
#[repr(i32)]
#[non_exhaustive]
pub enum Density {
Expand Down Expand Up @@ -432,7 +433,7 @@ impl Density {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum Keyboard {
Expand All @@ -446,7 +447,7 @@ pub enum Keyboard {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum Navigation {
Expand All @@ -461,7 +462,7 @@ pub enum Navigation {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum KeysHidden {
Expand All @@ -475,7 +476,7 @@ pub enum KeysHidden {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum NavHidden {
Expand All @@ -488,7 +489,7 @@ pub enum NavHidden {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)] // TODO: Ord?
#[repr(i32)]
#[non_exhaustive]
pub enum ScreenSize {
Expand All @@ -503,7 +504,7 @@ pub enum ScreenSize {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum ScreenLong {
Expand All @@ -516,7 +517,7 @@ pub enum ScreenLong {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum ScreenRound {
Expand All @@ -529,7 +530,7 @@ pub enum ScreenRound {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum WideColorGamut {
Expand All @@ -542,7 +543,7 @@ pub enum WideColorGamut {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum HDR {
Expand All @@ -555,7 +556,7 @@ pub enum HDR {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum LayoutDir {
Expand All @@ -568,7 +569,7 @@ pub enum LayoutDir {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum UiModeType {
Expand All @@ -586,7 +587,7 @@ pub enum UiModeType {
__Unknown(i32),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, FromPrimitive, IntoPrimitive)]
#[repr(i32)]
#[non_exhaustive]
pub enum UiModeNight {
Expand Down
Loading
Loading