ndk: Implement common traits where sensible, and drop some Ord#483
Open
MarijnS95 wants to merge 1 commit into
Open
ndk: Implement common traits where sensible, and drop some Ord#483MarijnS95 wants to merge 1 commit into
Ord#483MarijnS95 wants to merge 1 commit into
Conversation
daxpedda
approved these changes
Aug 14, 2024
Provided traits in the `ndk` crate are all over the place. Some pointer wrappers and regular enumerations derive `(Partial)Ord` even though there is no sense in using an ordering for these types. Others don't derive `(Partial)Eq` and `Hash` which makes it hard to compare if objects are the same (by-pointer) or to store them inside i.e. `HashMap`. Deriving these types follows Rust's [C-COMMON-TRAITS] convention. Additionally, sort `derives` by their relation, followed by sorting them alphabetically. [C-COMMON-TRAITS]: https://rust-lang.github.io/api-guidelines/interoperability.html#types-eagerly-implement-common-traits-c-common-traits
1e95ff3 to
8126cf3
Compare
MarijnS95
commented
Sep 3, 2024
Comment on lines
+17
to
19
| #[derive(Debug, PartialEq, Eq, Hash)] | ||
| #[doc(alias = "AAssetManager")] | ||
| pub struct AssetManager { |
Member
Author
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Provided traits in the
ndkcrate are all over the place. Some pointer wrappers and regular enumerations derive(Partial)Ordeven though there is no sense in using an ordering for these types. Others don't derive(Partial)EqandHashwhich makes it hard to compare if objects are the same (by-pointer) or to store them inside i.e.HashMap. Deriving these types follows Rust's C-COMMON-TRAITS convention.Additionally, sort
derivesby their relation, followed by sorting them alphabetically.Note that
Hashmay not be all too useful to store owned types as keys inHashMap, in case you have to temporarily increase the refcount on a pointer (i.e. aNativeWindowinside a callback viaNativeWindow::clone_from_ptr()) just to extract the element with that pointer, but that is hopefully something we can revise with #309. Additionally, some ways of solving that issue may involve addingClone, Copyto some non-refcounted types (assuming they have an external lifetime guarding it).TODO
ndk-systo be able to implement them on structures that ownffistructures;Iterwrappers?Ordon pointer wrappers after all, to store them in i.e.BTreeMapeven though their ordering has no useful definition?CC @daxpedda for suggestions based on rust-windowing/winit#3796 :)