965cc88a913f4923d2f2ceb506dbe34111caaeea
delegate! macro, a higher-level way to create Cocoa delegates (e.g. NSWindowDelegate) As @vbo mentioned in #205 the only way to create cocoa delegates such as NSWindowDelegate is to use the objc crate and it's a bit hard. I thought a macro for this would be useful. ## Example with NSWindowDelegate Without macro : ```rust let mut decl = ClassDecl::new("MyWindowDelegate", class!(NSObject)).unwrap(); decl.add_ivar::<id>("window"); decl.add_method(sel!(windowWillEnterFullScreen:), on_enter_fullscreen as extern fn(&Object, Sel, id)); let cl = decl.register(); let delegate: id = msg_send![cl, alloc]; (*delegate).set_ivar("window", window); window.setDelegate_(delegate); ``` With macro : ```rust window.setDelegate_(delegate!("MyWindowDelegate", { window: id = window, (windowWillEnterFullScreen:) => on_enter_fullscreen as extern fn(&Object, Sel, id) })); ``` <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/314) <!-- Reviewable:end -->
core-foundation-rs
Compatibility
Targets macOS 10.7 by default.
To enable features added in macOS 10.8, set Cargo feature mac_os_10_8_features. To have both 10.8 features and 10.7 compatibility, also set mac_os_10_7_support. Setting both requires weak linkage, which is a nightly-only feature as of Rust 1.19.
For more experimental but more complete, generated bindings take a look at https://github.com/michaelwu/RustKit.
Description
Languages
Rust
100%