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

Add RefEncode, and make Encode bounds required #14

Merged
merged 9 commits into from
Sep 1, 2021
Merged

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Sep 1, 2021

Adds RefEncode which represents types whoose pointers has an encoding. This means you now only have to implement RefEncode, and not both &Encode and &mut Encode (whom should always yield the same results anyway).

This setup is much better for generic code like in Message, which now requires implementations to implement RefEncode (which they should do anyhow).

This fixes SSheldon/rust-objc#80 because you're now required to annotate types that can be sent in a message (and then you can avoid Drop types), which vastly cuts down on footguns with using msg_send.

Also fixes SSheldon/rust-objc#26 by using the Encode/RefEncode split (instead of specialization).

Note: This design has already been explored in SSheldon/rust-objc#13, but was removed, I think because it didn't seem that nice, but anyhow, that was in 2015. Going through the bounds in objc_foundation it quickly becomes really, really difficult to do without RefEncode, because RefEncode is kinda fundamental.

Lastly, this fixes SSheldon/rust-objc-foundation#2 by going back to the original design from above.

Arguments as well as return types.

This is a breaking change, but the change is for the better since enabling the `verify_message` feature would break crates that weren't tested with that. Also, this opens up for more possibilities in improving how encodings work.
This means you now only have to implement `RefEncode`, and not both `&Encode` and `&mut Encode` (whom should always yield the same results anyway).

This setup is much better for generic code, including fixing a bunch of encoding issues in objc_foundation.

Also adds a bunch more documentation.
Implements Encode from pointers to pointers to pointers and so on.
- RefEncode (Encode already exist) for [T; LENGTH]
- Both for ManuallyDrop<T>
- Both for Pin<T>
- Both for NonNull<T>
- Both for Option<NonNull<T>>
Also moves EncodeArguments to objc_encode crate.
I can't imagine a case where you'd have a type that you can send messages to, but that can't be encoded as an Objective-C type-encoding, and having this a requirement makes downstream usage (e.g. objc_foundation) much nicer!
@madsmtm madsmtm added documentation Improvements or additions to documentation enhancement New feature or request labels Sep 1, 2021
Also moves the primary documentation into the README.md
@madsmtm madsmtm merged commit d857e90 into master Sep 1, 2021
@madsmtm madsmtm deleted the encode-bounds branch September 1, 2021 22:40
This was referenced Sep 5, 2021
@madsmtm madsmtm added this to the objc2 v0.3 milestone Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
1 participant