Skip to content
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

block2 0.2.0-alpha.6: Implementing Encode/RefEncode is bothersome and not always possible #16

Open
poliorcetics opened this issue Aug 30, 2022 · 1 comment

Comments

@poliorcetics
Copy link

I tried using the alpha 6 of block2, which lead me to objc2_encode which asked me to implement Encode and RefEncode

  1. It is bothersome to implement for the default case (a struct/union) with no particular semantics, in which case a derive proc macro could be provided.
  2. When using types from libc, e.g. stat, I either have to stop and not implement the traits or I have to go deep to find if there are pointers/members to other structs where I have to do the same until I reach only base types. In the case of pointers I don't even know how I would do it ? A mimic struct defined locally which implements Encode ?

I don't know if there is a good solution to 2. sadly, because adding a dep in libc on objc2_encode is certainly not going to work.

@madsmtm
Copy link

madsmtm commented Aug 30, 2022

Hey, it seems like this issue belongs in the objc2 repository.

There you will also find that a derive macro for Encode/RefEncode is being worked on (albeit low priority right now).

Also, you can "cheat" a bit with types like stat, and just use a c_void pointer in it's place:

use std::ffi::c_void;
use libc::stat;
use block2::ConcreteBlock;

let block = ConcreteBlock::new(|s: *const c_void| {
    let s: *const stat = s.cast();
    // Use `s` here
});
// ...

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

No branches or pull requests

2 participants