Skip to content

Allow Drop types in ivars #254

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

Merged
merged 3 commits into from
Aug 31, 2022
Merged

Allow Drop types in ivars #254

merged 3 commits into from
Aug 31, 2022

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Aug 29, 2022

Part of #30.

The desire is to allow using Box, Id and WeakId (and at some point Arc, Rc and the corresponding Weak) inside instance variables.

This is accomplished using a new user-facing type IvarDrop<T> (because of current coherence limitations in how Box/#[fundamental] types work).

Usage:

use objc2::foundation::NSObject;
use objc2::declare::IvarDrop;
use objc2::{declare_class, ClassType};

declare_class!(
    struct MyObject {
        ivar: IvarDrop<Box<i32>>,
    }

    unsafe impl ClassType for MyObject {
        type Super = NSObject;
    }

    // Later on, initialize it with `Ivar::write`

    // A `dealloc` method is generated automatically
);

@madsmtm madsmtm added enhancement New feature or request A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates labels Aug 29, 2022
@madsmtm madsmtm force-pushed the ivar-drop branch 2 times, most recently from 7040f6e to 8fdab4a Compare August 29, 2022 22:26
@madsmtm madsmtm marked this pull request as ready for review August 29, 2022 22:26
@madsmtm madsmtm merged commit 6caf8aa into master Aug 31, 2022
@madsmtm madsmtm deleted the ivar-drop branch August 31, 2022 19:20
@madsmtm madsmtm mentioned this pull request Aug 31, 2022
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant