For that, we’d need to package the executable into an app bundle.Īn easy way to create an app bundle which launches Rust code is to create a Cocoa app with a Rust and dependent app target. While we can use the snippets of the cocoa crate to run an executable, the executable is not packaged as an app bundle, which would be suitable for having an app icon, putting an app in the dock, or being registered as a default application (like being the mail client used for mailto: links, for example). I explored some options such as implementing a Drop trait to automatically discard Objective-C objects once the Rust reference goes out of scope, but this behavior is not always desirable, especially when working with references to applications and windows which are expected to stay for the life time of the application, or at least longer than the current scope. Resources still need to be released (or auto-released, if applicable) when they are no longer needed, but classes became much easier to use. The class can now be used directly, and without unsafe: let greeting = NSString::from( "hello") Here’s an example of creating an NSObject: unsafe The objc crate in particular provides the msg_send! macro, which is a basic interface to messaging Objective-C objects. There are already crates for working with the Objective-C runtime, such as the objc and block crates, which are for using the runtime directly and interfacing with Apple’s block extensions respectively. This experiment is about applying Cocoa and Rust knowledge to create something safe and yet easy to work with. I’ve done iOS and Mac application development for many years and it’s worth noting that the hardest part of Cocoa development has always been learning the frameworks rather than the languages. Most of these projects have been replacements for existing scripts in my workflows or new command line tools, but I wanted to create a Mac application and determine if it would benefit from Rust’s memory efficiency, safety, and robust library ecosystem. Rust is a systems programming language focused on speed and safe concurrency, and which I’ve been using for personal projects heavily since the 1.0 release last year.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |