1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
#[doc(hidden)]
#[macro_export]
macro_rules! __inner_declare_class {
{@rewrite_methods @$output_type:ident @$builder:ident} => {};
{
@rewrite_methods
@$output_type:ident
@$builder:ident
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident($($args:tt)*) $(-> $ret:ty)? $body:block
$($rest:tt)*
} => {
$crate::__inner_declare_class! {
@rewrite_methods_inner
@$output_type
@$builder
// Split args out so that we can match on `self`, while still use
// it as a function argument
($($args)*)
$(#[$m])*
@sel($($sel)+)
fn $name($($args)*) $(-> $ret)? $body
}
$crate::__inner_declare_class! {
@rewrite_methods
@$output_type
@$builder
$($rest)*
}
};
// Instance method
{
@rewrite_methods_inner
@$output_type:ident
@$builder:ident
(&mut self $($__rest_args:tt)*)
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident(
&mut $self:ident
$(, $($rest_args:tt)*)?
) $(-> $ret:ty)? $body:block
} => {
$crate::__inner_declare_class! {
@$output_type
@instance_method
@sel($($sel)*)
@$name
@$builder
@($($($rest_args)*)?)
$(#[$m])*
extern "C" fn $name(
&mut $self,
_: $crate::objc2::runtime::Sel,
$($($rest_args)*)?
) $(-> $ret)? $body
}
};
{
@rewrite_methods_inner
@$output_type:ident
@$builder:ident
(&self $($__rest_args:tt)*)
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident(
&$self:ident
$(, $($rest_args:tt)*)?
) $(-> $ret:ty)? $body:block
} => {
$crate::__inner_declare_class! {
@$output_type
@instance_method
@sel($($sel)*)
@$name
@$builder
@($($($rest_args)*)?)
$(#[$m])*
extern "C" fn $name(
&$self,
_: $crate::objc2::runtime::Sel,
$($($rest_args)*)?
) $(-> $ret)? $body
}
};
{
@rewrite_methods_inner
@$output_type:ident
@$builder:ident
(
mut self: $__self_ty:ty
$(, $($__rest_args:tt)*)?
)
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident(
mut $self:ident: $self_ty:ty
$(, $($rest_args:tt)*)?
) $(-> $ret:ty)? $body:block
} => {
$crate::__inner_declare_class! {
@$output_type
@instance_method
@sel($($sel)*)
@$name
@$builder
@($($($rest_args)*)?)
$(#[$m])*
extern "C" fn $name(
mut $self: $self_ty,
_: $crate::objc2::runtime::Sel,
$($($rest_args)*)?
) $(-> $ret)? $body
}
};
{
@rewrite_methods_inner
@$output_type:ident
@$builder:ident
(
self: $__self_ty:ty
$(, $($__rest_args:tt)*)?
)
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident(
$self:ident: $self_ty:ty
$(, $($rest_args:tt)*)?
) $(-> $ret:ty)? $body:block
} => {
$crate::__inner_declare_class! {
@$output_type
@instance_method
@sel($($sel)*)
@$name
@$builder
@($($($rest_args)*)?)
$(#[$m])*
extern "C" fn $name(
$self: $self_ty,
_: $crate::objc2::runtime::Sel,
$($($rest_args)*)?
) $(-> $ret)? $body
}
};
// Class method
{
@rewrite_methods_inner
@$output_type:ident
@$builder:ident
($($__args:tt)*)
$(#[$m:meta])*
@sel($($sel:tt)+)
fn $name:ident(
$($args:tt)*
) $(-> $ret:ty)? $body:block
} => {
$crate::__inner_declare_class! {
@$output_type
@class_method
@sel($($sel)*)
@$name
@$builder
@($($args)*)
$(#[$m])*
extern "C" fn $name(
_: &$crate::objc2::runtime::Class,
_: $crate::objc2::runtime::Sel,
$($args)*
) $(-> $ret)? $body
}
};
{
@method_out
@$method_type:ident
@sel($($sel:tt)*)
@$name:ident
@$builder:ident
@($($builder_args:tt)*)
$method:item
} => {
$method
};
{
@register_out
@class_method
@sel($($sel:tt)*)
@$name:ident
@$builder:ident
@($($builder_args:tt)*)
$method:item
} => {
$builder.add_class_method(
$crate::objc2::sel!($($sel)*),
$crate::__inner_declare_class! {
@cast_extern_fn
@$name
$($builder_args)*
},
);
};
{
@register_out
@instance_method
@sel($($sel:tt)*)
@$name:ident
@$builder:ident
@($($builder_args:tt)*)
$method:item
} => {
$builder.add_method(
$crate::objc2::sel!($($sel)*),
$crate::__inner_declare_class! {
@cast_extern_fn
@$name
$($builder_args)*
},
);
};
// Create the `as extern "C" fn(...) -> _` cast
//
// TODO: Investigate if there's a better way of doing this
{
@cast_extern_fn
@$name:ident
$(,)?
} => {
Self::$name as extern "C" fn(_, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty,
$($param8:ident)? $(_)?: $param8_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty,
$($param8:ident)? $(_)?: $param8_ty:ty,
$($param9:ident)? $(_)?: $param9_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty,
$($param8:ident)? $(_)?: $param8_ty:ty,
$($param9:ident)? $(_)?: $param9_ty:ty,
$($param10:ident)? $(_)?: $param10_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty,
$($param8:ident)? $(_)?: $param8_ty:ty,
$($param9:ident)? $(_)?: $param9_ty:ty,
$($param10:ident)? $(_)?: $param10_ty:ty,
$($param11:ident)? $(_)?: $param11_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _, _, _, _, _) -> _
};
{
@cast_extern_fn
@$name:ident
$($param1:ident)? $(_)?: $param1_ty:ty,
$($param2:ident)? $(_)?: $param2_ty:ty,
$($param3:ident)? $(_)?: $param3_ty:ty,
$($param4:ident)? $(_)?: $param4_ty:ty,
$($param5:ident)? $(_)?: $param5_ty:ty,
$($param6:ident)? $(_)?: $param6_ty:ty,
$($param7:ident)? $(_)?: $param7_ty:ty,
$($param8:ident)? $(_)?: $param8_ty:ty,
$($param9:ident)? $(_)?: $param9_ty:ty,
$($param10:ident)? $(_)?: $param10_ty:ty,
$($param11:ident)? $(_)?: $param11_ty:ty,
$($param12:ident)? $(_)?: $param12_ty:ty $(,)?
} => {
Self::$name as extern "C" fn(_, _, _, _, _, _, _, _, _, _, _, _, _, _) -> _
};
}
/// Declare a new Objective-C class.
///
/// This is mostly just a convenience macro on top of [`extern_class!`] and
/// the functionality in the [`objc2::declare`] module, but it can really help
/// with cutting down on boilerplate, in particular when defining delegate
/// classes!
///
///
/// # Specification
///
/// This macro consists of three parts; the class definition, the method
/// definition, and the protocol definition.
///
///
/// ## Class and ivar definition
///
/// The class definition works a lot like [`extern_class!`], with the added
/// functionality that you can define custom instance variables on your class,
/// which are then wrapped in a [`objc2::runtime::Ivar`] and made accessible
/// through the class. (E.g. you can use `self.my_ivar` as if it was a normal
/// Rust struct).
///
/// Note that the class name should be unique across the entire application!
/// As a tip, you can declare the class with the desired unique name like
/// `MyCrateCustomObject` using this macro, and then expose a renamed type
/// alias like `pub type CustomObject = MyCrateCustomObject;` instead.
///
/// The class is guaranteed to have been created and registered with the
/// Objective-C runtime after the associated function `class` has been called.
///
///
/// ## Method definition
///
/// Within the `impl` block you can define two types of functions;
/// ["associated functions"] and ["methods"]. These are then mapped to the
/// Objective-C equivalents "class methods" and "instance methods". In
/// particular, if you use `self` your method will be registered as an
/// instance method, and if you don't it will be registered as a class method.
///
/// The desired selector can be specified using a special `@sel(my:selector:)`
/// directive directly before the function definition.
///
/// A transformation step is performed on the functions (to make them have the
/// correct ABI) and hence they shouldn't really be called manually. (You
/// can't mark them as `pub` for the same reason). Instead, define a new
/// function that calls it via. [`objc2::msg_send!`].
///
/// ["associated functions"]: https://doc.rust-lang.org/reference/items/associated-items.html#methods
/// ["methods"]: https://doc.rust-lang.org/reference/items/associated-items.html#methods
///
///
/// ## Protocol definition
///
/// You can specify the protocols that the class should implement, along with
/// any required methods for said protocols.
///
/// The methods work exactly as normal, they're only put "under" the protocol
/// definition to make things easier to read.
///
///
/// # Safety
///
/// Using this macro requires writing a few `unsafe` markers:
///
/// `unsafe struct ...` has the following safety requirements:
/// - Same as [`extern_class!`] (the inheritance chain has to be correct).
/// - Any instance variables you specify must either be able to be created
/// using [`MaybeUninit::zeroed`], or be properly initialized in an `init`
/// method.
///
/// `unsafe impl { ... }` asserts that the types match those that are expected
/// when the method is invoked from Objective-C. Note that there are no
/// safe-guards here; you can easily write `i8`, but if Objective-C thinks
/// it's an `u32`, it will cause UB when called!
///
/// `unsafe impl protocol ... { ... }` requires that all required methods of
/// the specified protocol is implemented, and that any extra requirements
/// (implicit or explicit) that the protocol has are upheld. The methods in
/// this definition has the same safety requirements as above.
///
/// [`MaybeUninit::zeroed`]: core::mem::MaybeUninit::zeroed
///
///
/// # Examples
///
/// Declare a class `MyCustomObject` that inherits `NSObject`, has a few
/// instance variables and methods, and implements the `NSCopying` protocol.
///
/// ```
/// use std::os::raw::c_int;
/// use objc2::{msg_send, msg_send_bool, msg_send_id};
/// use objc2::rc::{Id, Owned};
/// use objc2::runtime::Bool;
/// use objc2_foundation::{declare_class, NSCopying, NSObject, NSZone};
/// #
/// # #[cfg(feature = "gnustep-1-7")]
/// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
///
/// declare_class! {
/// unsafe struct MyCustomObject: NSObject {
/// foo: u8,
/// pub bar: c_int,
/// }
///
/// unsafe impl {
/// @sel(initWithFoo:)
/// fn init_with(&mut self, foo: u8) -> Option<&mut Self> {
/// let this: Option<&mut Self> = unsafe {
/// msg_send![super(self, NSObject::class()), init]
/// };
/// this.map(|this| {
/// // TODO: Initialization through MaybeUninit
/// // (The below is only safe because these variables are
/// // safe to initialize with `MaybeUninit::zeroed`).
/// *this.foo = foo;
/// *this.bar = 42;
/// this
/// })
/// }
///
/// @sel(foo)
/// fn __get_foo(&self) -> u8 {
/// *self.foo
/// }
///
/// @sel(myClassMethod)
/// fn __my_class_method() -> Bool {
/// Bool::YES
/// }
/// }
///
/// unsafe impl protocol NSCopying {
/// @sel(copyWithZone:)
/// fn copy_with_zone(&self, _zone: *const NSZone) -> *mut Self {
/// let mut obj = Self::new(*self.foo);
/// *obj.bar = *self.bar;
/// obj.autorelease_return()
/// }
/// }
/// }
///
/// impl MyCustomObject {
/// pub fn new(foo: u8) -> Id<Self, Owned> {
/// let cls = Self::class();
/// unsafe { msg_send_id![msg_send_id![cls, alloc], initWithFoo: foo].unwrap() }
/// }
///
/// pub fn get_foo(&self) -> u8 {
/// unsafe { msg_send![self, foo] }
/// }
///
/// pub fn my_class_method() -> bool {
/// unsafe { msg_send_bool![Self::class(), myClassMethod] }
/// }
/// }
///
/// unsafe impl NSCopying for MyCustomObject {
/// type Ownership = Owned;
/// type Output = Self;
/// }
///
/// fn main() {
/// let obj = MyCustomObject::new(3);
/// assert_eq!(*obj.foo, 3);
/// assert_eq!(*obj.bar, 42);
///
/// let obj = obj.copy();
/// assert_eq!(obj.get_foo(), 3);
///
/// assert!(MyCustomObject::my_class_method());
/// }
/// ```
///
/// Approximately equivalent to the following Objective-C code.
///
/// ```text
/// #import <Foundation/Foundation.h>
///
/// @interface MyCustomObject: NSObject <NSCopying> {
/// // Public ivar
/// int bar;
/// }
///
/// - (instancetype)initWithFoo:(uint8_t)foo;
/// - (uint8_t)foo;
/// + (BOOL)myClassMethod;
///
/// @end
///
///
/// @implementation MyCustomObject {
/// // Private ivar
/// uint8_t foo;
/// }
///
/// - (instancetype)initWithFoo:(uint8_t)foo_arg {
/// self = [super init];
/// if (self) {
/// self->foo = foo_arg;
/// self->bar = 42;
/// }
/// return self;
/// }
///
/// - (uint8_t)foo {
/// return self->foo; // Or just `foo`
/// }
///
/// + (BOOL)myClassMethod {
/// return YES;
/// }
///
/// // NSCopying
///
/// - (id)copyWithZone:(NSZone *)_zone {
/// MyCustomObject* obj = [[MyCustomObject alloc] initWithFoo: self->foo];
/// obj->bar = self->bar;
/// return obj;
/// }
///
/// @end
/// ```
#[macro_export]
macro_rules! declare_class {
{
$(#[$m:meta])*
unsafe $v:vis struct $name:ident: $inherits:ty $(, $inheritance_rest:ty)* {
$($ivar_v:vis $ivar:ident: $ivar_ty:ty,)*
}
$(
$(#[$impl_m:meta])*
unsafe impl $(protocol $protocol:ident)? {
$($methods:tt)*
}
)*
} => {
$(
#[allow(non_camel_case_types)]
$ivar_v struct $ivar {
__priv: (),
}
unsafe impl $crate::objc2::declare::IvarType for $ivar {
type Type = $ivar_ty;
const NAME: &'static str = stringify!($ivar);
}
)*
$crate::__inner_extern_class! {
@__inner
$(#[$m])*
// SAFETY: Upheld by caller
unsafe $v struct $name<>: $inherits, $($inheritance_rest,)* $crate::objc2::runtime::Object {
// SAFETY:
// - The ivars are in a type used as an Objective-C object.
// - The instance variable is defined in the exact same manner
// in `class` below.
// - Rust prevents having two fields with the same name.
// - Caller upholds that the ivars are properly initialized.
$($ivar_v $ivar: $crate::objc2::declare::Ivar<$ivar>,)*
}
}
// Creation
impl $name {
#[doc = concat!(
"Get a reference to the Objective-C class `",
stringify!($name),
"`.",
"\n\n",
"May register the class if it wasn't already.",
)]
// TODO: Allow users to configure this?
$v fn class() -> &'static $crate::objc2::runtime::Class {
// TODO: Use `core::cell::LazyCell`
use $crate::__std::sync::Once;
use $crate::objc2::declare::ClassBuilder;
use $crate::objc2::runtime::Protocol;
static REGISTER_CLASS: Once = Once::new();
REGISTER_CLASS.call_once(|| {
let superclass = <$inherits>::class();
let err_str = concat!(
"could not create new class ",
stringify!($name),
". Perhaps a class with that name already exists?",
);
let mut builder = ClassBuilder::new(stringify!($name), superclass).expect(err_str);
$(
builder.add_ivar::<<$ivar as $crate::objc2::declare::IvarType>::Type>(
<$ivar as $crate::objc2::declare::IvarType>::NAME
);
)*
$(
// Implement protocol if any specified
$(
let err_str = concat!("could not find protocol ", stringify!($protocol));
builder.add_protocol(Protocol::get(stringify!($protocol)).expect(err_str));
)?
// Implement methods
// SAFETY: Upheld by caller
unsafe {
$crate::__inner_declare_class! {
@rewrite_methods
@register_out
@builder
$($methods)*
}
}
)*
let _cls = builder.register();
});
$crate::objc2::class!($name)
}
}
// Methods
$(
$(#[$impl_m])*
impl $name {
$crate::__inner_declare_class! {
@rewrite_methods
@method_out
@__builder
$($methods)*
}
}
)*
};
}