Skip to content

Commit 1b4230d

Browse files
committed
Avoid breaking change in cf_type! macro
This macro is used at present in the `sysinfo` crate.
1 parent 0ed3c8e commit 1b4230d

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

framework-crates/objc2-core-foundation/src/__cf_macro_helpers.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ pub use core::ops::Deref;
99
pub use core::primitive::bool;
1010
pub use core::stringify;
1111
#[cfg(feature = "objc2")]
12-
pub use objc2::encode::{Encode, Encoding, RefEncode};
13-
#[cfg(feature = "objc2")]
14-
pub use objc2::runtime::AnyObject;
15-
#[cfg(feature = "objc2")]
16-
pub use objc2::Message;
12+
pub use objc2::cf_objc2_type;
1713

1814
#[cfg(feature = "CFBase")]
1915
pub use crate::CFTypeID;

framework-crates/objc2-core-foundation/src/cf_type.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#[macro_export]
3030
macro_rules! cf_type {
3131
(
32+
$(#[encoding_name = $encoding_name:literal])? // TODO(breaking): Remove this.
3233
unsafe impl $(<$($generic:ident : ?$sized:ident),* $(,)?>)? $ty:ident $(<$($generic_param:ident),* $(,)?>)? $(: $superclass:ty)? {}
3334
) => {
3435
// Reflexive AsRef impl.
@@ -45,6 +46,12 @@ macro_rules! cf_type {
4546
$crate::__cf_type_needs_cf_base!(impl ($(<$($generic : ?$sized),*>)?) $ty $(<$($generic_param),*>)?);
4647

4748
$crate::__cf_type_superclass!(impl ($(<$($generic : ?$sized),*>)?) $ty $(<$($generic_param),*>)? $(: $superclass)?);
49+
50+
// Objective-C interop
51+
$crate::__cf_type_objc2!(
52+
impl ($(<$($generic : ?$sized),*>)?) $ty $(<$($generic_param),*>)?;
53+
$($encoding_name)?
54+
);
4855
};
4956
}
5057

@@ -175,3 +182,22 @@ macro_rules! __cf_type_no_superclass {
175182
macro_rules! __cf_type_no_superclass {
176183
(impl ($($generics:tt)*) $ty:ty) => {};
177184
}
185+
186+
#[cfg(feature = "objc2")]
187+
#[doc(hidden)]
188+
#[macro_export]
189+
macro_rules! __cf_type_objc2 {
190+
(impl ($($generics:tt)*) $ty:ty;) => {};
191+
(impl ($($generics:tt)*) $ty:ty; $encoding:literal) => {
192+
$crate::__cf_macro_helpers::cf_objc2_type!(
193+
unsafe impl $($generics)* for RefEncode<$encoding> $ty {}
194+
);
195+
};
196+
}
197+
198+
#[cfg(not(feature = "objc2"))]
199+
#[doc(hidden)]
200+
#[macro_export]
201+
macro_rules! __cf_type_objc2 {
202+
($($t:tt)*) => {};
203+
}

0 commit comments

Comments
 (0)