You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that block2 requires arguments to implement Encode, but it doesn't do anything with that trait on the arguments. Blocks have the same encoding regardless. So does this really need to be a requirement?
The text was updated successfully, but these errors were encountered:
The ABI that block2 builds upon allows for legacy reasons that blocks don't specify their encoding, though ideally they should (search for signature in that document). Since we can't easily generate them in const/static contexts yet (requires some form of const generics, see #70), we make use of the legacy option and don't provide the block's encoding, yet!
More importantly though, the bound is there to prevent accidentally passing types that are not FFI-safe, such as Vec<T>, or ZSTs like (). So mostly there to help with ensuring soundness.
Do you have a use-case for passing a non-Encode type?
I'm going to keep the Encode requirement on blocks because it is a great boon to safety.
If you want to pass a specific non-Encode type, you can do something like the following:
use block2::ConcreteBlock;use objc2::encode::{Encode,Encoding};#[repr(transparent)]structHelper(Box<u32>);// Or whatever type you need to pass acrossunsafeimplEncodeforHelper{// Or whatever encoding would be most descriptive for your typeconstENCODING:Encoding = Encoding::Pointer(Encoding::Void);}let block = ConcreteBlock::new(|helper:Helper| {let my_type = helper.0;// Do whatever you need to do with your type});let block = block.copy();let my_type = Box::new(5);unsafe{ block.call((Helper(my_type),))};
I noticed that block2 requires arguments to implement
Encode
, but it doesn't do anything with that trait on the arguments. Blocks have the same encoding regardless. So does this really need to be a requirement?The text was updated successfully, but these errors were encountered: