rust-objc-id
rust-objc-id copied to clipboard
Default Id to shared by renaming {Id => OwnedId} and {ShareId => Id}
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.
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.