Skip to content

Making Id::retain safer #399

@madsmtm

Description

@madsmtm

For some things like NSMutableString (and by extension, NSString), calling Id::retain on &T cannot be safe, since there could be a mutable reference to it somewhere else in the program (and the lifetime is erased by calling Id::retain, that's kinda the whole point).

The solution there is to use NSCopying::copy to instead store a copy of your string (which is cheap when given &NSString, and correct when given &NSMutableString).

But for types like NSView and NSWindow, this is overly restrictive, since we know there can never be a mutable reference to these (they always use interior mutability); so perhaps we can make a trait for expressing this? (This comes up especially often in user-defined init methods).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesenhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions