Skip to content

Commit

Permalink
Add public EncodeReturn, EncodeArgument and EncodeArguments
Browse files Browse the repository at this point in the history
And make the two conversion traits ConvertReturn and ConvertArgument in a sense "more" private
  • Loading branch information
madsmtm committed Sep 3, 2023
1 parent c28f5ca commit ce2b0a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/block.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use core::marker::PhantomData;
use core::mem;

use objc2::encode::__unstable::EncodeReturn;
use objc2::encode::{Encode, Encoding, RefEncode};
use objc2::encode::{EncodeArgument, EncodeReturn, Encoding, RefEncode};

use crate::ffi;

/// Types that may be used as the arguments of an Objective-C block.
///
/// This is implemented for tuples of up to 12 arguments, where each argument
/// implements [`Encode`].
/// implements [`EncodeArgument`].
///
///
/// # Safety
Expand All @@ -28,7 +27,7 @@ pub unsafe trait BlockArguments: Sized {

macro_rules! block_args_impl {
($($a:ident: $t:ident),*) => (
unsafe impl<$($t: Encode),*> BlockArguments for ($($t,)*) {
unsafe impl<$($t: EncodeArgument),*> BlockArguments for ($($t,)*) {
#[inline]
unsafe fn __call_block<R: EncodeReturn>(
invoke: unsafe extern "C" fn(),
Expand Down
10 changes: 5 additions & 5 deletions src/concrete_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use core::ops::Deref;
use core::ptr;
use std::os::raw::c_ulong;

use objc2::encode::__unstable::EncodeReturn;
use objc2::encode::{Encode, Encoding, RefEncode};
use objc2::encode::{EncodeArgument, EncodeReturn, Encoding, RefEncode};

use crate::{ffi, Block, BlockArguments, RcBlock};

Expand All @@ -17,7 +16,8 @@ mod private {
/// Types that may be converted into a [`ConcreteBlock`].
///
/// This is implemented for [`Fn`] closures of up to 12 arguments, where each
/// argument and the return type implements [`Encode`].
/// argument implements [`EncodeArgument`] and the return type implements
/// [`EncodeReturn`].
///
///
/// # Safety
Expand All @@ -37,12 +37,12 @@ macro_rules! concrete_block_impl {
concrete_block_impl!($f,);
);
($f:ident, $($a:ident : $t:ident),*) => (
impl<$($t: Encode,)* R: EncodeReturn, X> private::Sealed<($($t,)*)> for X
impl<$($t: EncodeArgument,)* R: EncodeReturn, X> private::Sealed<($($t,)*)> for X
where
X: Fn($($t,)*) -> R,
{}

unsafe impl<$($t: Encode,)* R: EncodeReturn, X> IntoConcreteBlock<($($t,)*)> for X
unsafe impl<$($t: EncodeArgument,)* R: EncodeReturn, X> IntoConcreteBlock<($($t,)*)> for X
where
X: Fn($($t,)*) -> R,
{
Expand Down
2 changes: 1 addition & 1 deletion src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ops::Deref;
use core::ptr;
use std::os::raw::c_ulong;

use objc2::encode::__unstable::EncodeReturn;
use objc2::encode::EncodeReturn;

use super::{ffi, Block};
use crate::BlockArguments;
Expand Down

0 comments on commit ce2b0a9

Please sign in to comment.