Skip to content

Implementing protocol methods with Id<_, _> return types #317

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

Closed
ericmarkmartin opened this issue Dec 30, 2022 · 2 comments · Fixed by #354
Closed

Implementing protocol methods with Id<_, _> return types #317

ericmarkmartin opened this issue Dec 30, 2022 · 2 comments · Fixed by #354

Comments

@ericmarkmartin
Copy link

ericmarkmartin commented Dec 30, 2022

Suppose we have a protocol P with method f(&self) -> Id<NSObject, Shared>. If we use declare_class! to implement this protocol for a new type...

declare_class!(
  struct C {
    // This is unrelated to this ticket but I can't figure out how to do empty structs in `declare_class`
    filler: u8
  }

  unsafe impl ConformsTo<P> for C {
    #[method(f)]
    fn f(&self) -> Id<NSObject, Shared> {
      unimplemented!()
    }
  }
)

We see

the trait Encodeis not implemented foricrate::objc2::rc::Id<NSObject, Shared>`

in the macro expansion because it generates

<Id<NSObject, Shared> as $crate::encode::EncodeConvert>::__into_inner({
  $crate::panicking::panic("not implemented")
})

And Id<_, _> doesn't implement EncodeConvert

@madsmtm
Copy link
Owner

madsmtm commented Dec 31, 2022

You can't use #[method(f)], because returning Id requires doing extra work based on the selector, akin to msg_send! vs. msg_send_id!.

Allowing this is indeed on my todolist, see #282.

Until the above issue is resolved, you can return *mut NSObject instead.

@madsmtm
Copy link
Owner

madsmtm commented Dec 31, 2022

This is unrelated to this ticket but I can't figure out how to do empty structs in declare_class

This should work:

declare_class!(
  struct C {}

  // ...
)

Though you're right, declare_class! should allow an empty struct C;, I've fixed that in #318.

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

Successfully merging a pull request may close this issue.

2 participants