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

Default Id to shared by renaming {Id => OwnedId} and {ShareId => Id} #4

Open
syntheorem opened this issue Oct 29, 2016 · 1 comment

Comments

@syntheorem
Copy link

This is purely an ergonomic issue and therefore subjective, and it's also a breaking change. But since you're still at 0.1 this seems like a good time for this kind of feedback :)

Basically, I think shared should be the default because all Objective-C objects can be shared by default because they all have reference counting. When I see an id in Objective-C code, I assume it can be shared until proven otherwise. I would like to be able to use the same mindset with Rust, except that once I as the programmer prove that it is not shared, I can explicitly use an OwnedId and have that invariant enforced by the compiler (at least on the Rust side of things).

Additionally, since the owned vs shared aspect is not enforced in any way on the Objective-C side of things, that means it's far more safe to assume that everything is shared by default (even init methods might retain and share self with some other object, so there is no guarantee that even an object you just created is owned in the Rust sense). So it makes more sense to me to have the shared version be the default, only switching to the owned variant when safe and necessary.

@SSheldon
Copy link
Owner

Yeah this is great feedback. I was working on a UIKit wrapper and ended up needing basically everything to be a ShareId, so I get where you're coming from.

This is a good thing to mull over! I haven't been working on this crate very actively; it's really only used by the objc-foundation crate (and its users). Not having wider adoption has slowed it down; I never found a design that worked for the cocoa crate, as detailed in SSheldon/rust-objc#24. Instead, each project using cocoa has ended up making its own id, like IdRef in glutin.

madsmtm added a commit to madsmtm/objc2 that referenced this issue Sep 9, 2021
This is a usability degradation, but before we know more about actual usage patterns this is the safer option; users will have to explicitly specify the ownership they're expecting.

See SSheldon/rust-objc-id#4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants