Closed
Description
After #21 I can go through objc2-foundation
and re-evaluate how we should do the ownership stuff. Especially difficult with generic objects like NSArray
!
The idea is it we fix the soundness issues in SSheldon/rust-objc-foundation#10, see my comment there.
Probably some rework of INSObject
is required.
Should also figure out the safety of "downgrading" (e.g. Moved to #58&MyObject -> &NSObject
)? And from there &NSObject -> Id<NSObject, Shared>
(which deletes the original lifetime). What about when MyObject<'a>
itself carries lifetime information? Maybe add lifetime to Id
?
Also, should we add an Moved to #66ObjectType
/RetainAble
/... type, since not all Message
types can actually be used in Id
?
Idea:
unsafe trait INSObject {
type Own: Ownership;
// ...
fn new() -> Id<Self, O> { ... }
}
unsafe trait INSCopying: INSObject {
fn copy(&self) -> Id<Self, Shared>;
}
unsafe trait INSMutableCopying: INSObject<Own = Owned> {
fn copy_mut(&self) -> Id<Self, Owned>;
}
unsafe impl INSObject for NSString {
type Own = Shared; // This means there may never exist an `&mut NSString` (and by extension no `Id<NSString, Owned>`)!
}
unsafe impl INSObject for NSMutableString {
type Own = Owned; // Both `Id<NSString, Owned>` and `Id<NSString, Shared>` are possible
}