Rust For Mac

This video should help you to increase your FPS and performance in Rust, however, if this video does not help you it is likely due to your computer specs not. Completion and highlighting While on Linux VSCode with the Rust plugin seems to work more or less out of the box, on a Mac I needed to spend some time configuring it. First things first though, let’s start by installing Rust version manager, rustup. Curl -sSf sh We will be using nightly version of rust as to have one version that can compile all of our tools.

Mr. Mac Rust

Rust for mac free

Mr. Landon Northcutt

Diversified Sales, LLC

166 South Belknap

Stephenville, Texas 76401-4202

Breach of Fiduciary Duties to and Breach of Contract with Star Hospital Solutions, L.L.C. (“Star”).

Mac Rust attempted to trick hospitals into working with his new company. He cleverly and deceptively—formed a competing entity and named it “Star Management Solutions LLC” instead of Star Hospital Solution. And then he called it “star” as well in order to usurp business from his partners.

If Mac Rust does not agree to immediately cease and desist all competitive activities, the real Star will enforce its right to an injunction in Court and aggressively pursue all available remedies to hold Mac Rust legally and financially responsible for his violations of fiduciary duties and his contracts.

Mr Rust has a noncompetition agreement with Stare that expressly prohibits competition through restructured entities like the fake Star Mac Rust has formed and grants the real Star the right to injunctive relief in court. Equally important are the duties to which Mac Rust committed both as Member and as Manager: “certain fiduciary duties, duty of loyalty and other similar duties.” Mac Rust and his entities all knowingly participated in the breaches of fiduciary duties.

Yet Mac Rust ’s actions fell far short of the duty of utmost good faith and loyalty. To the contrary, once several hospitals were ready to sign with the real Star, Rust and his partner Landon Northcutt got greedy.

Mac Rust and Landon Northcutt decided they could duplicate the Star model, thereby making all the profits for themselves and cutting out their original Star partners. So just one month into the deal, in breach of their duties and covenants, they called on Star prospect hospitals (see attached) as “star” representatives and presented them altered documents in hopes they could switch the unsuspecting hospitals to the fake star.

In fact, we have now learned that on July 7, 2017—while Mac Rust and Landon Northcutt were still Members and Managers of the real Star and a full month before their sudden resignation— Rust and Landon Northcutt signed a contract with ABC General Hospital on behalf of the fake star leveraging the efforts and investment their deal partners made for their own benefit. Thankfully the manager of ABC General Hospital caught the fraud. Nonetheless, Rust and Landon Northcutt caused confusion in the marketplace about which star was real and which was a scam, irreparably damaging the real Star.

Rust For Mac

Additionally, Mac Rust and Landon Northcutt set up a second entity called “On Campus Laboratory Management LLC” (“On Campus”) to position themselves with new rural Texas hospitals that had not yet been as exposed to the Star name. Included in this target group was ABC Medical Center. The real Star spent months developing this prospect, but Mac Rust and Landon Northcutt usurped the deal and On Campus is now positioning to provide the blood testing at ABC. The real Star demands disgorgement of all profits Mac Rust and Landon Northcutt illegally obtain(ed) in that transaction and any others.

On August 3, 2017 at 3:00 p.m., a Membership/Management meeting of the real Star was called in Dallas, Texas. Neither Mac Rust nor Landon Northcutt showed up. Instead, 10 minutes into the meeting Rust and Landon Northcutt purported to have themselves and Diversified Sales LLC (“Diversified”) resign from their roles. Regardless, their duties and their covenants remain intact. Notably, in furtherance of the deception, Mr. Rust has started referring to himself as “Jay” instead of “Mac” in order to appear as if he weren’t a Manager of the real Star.

The misconduct of Mac Rust and Landon Northcutt before and after their resignation from Star not only gives rise to substantial actual and exemplary damages but also triggers injunctive relief under the Texas Uniform Trade Secret Act—for their theft of the real Star’s client list and other proprietary business information. TEX. CIV. PRAC. & REM. CODE §§ 134A.002-3 (“‘trade secret’ means information, including . . . list of actual or potential customers or suppliers;” providing for injunctive relief). And under the Texas Uniform Fraudulent Transfer Act—for your conveyance of the real Star’s contracts. TEX. BUS. & COMM. CODE §§ 24.002-8 (“‘property’ means anything that may be the subject of ownership;” providing for injunctive relief).

Shane Bledsoe and others stand ready to testify to your scheme at both the injunctive and damages phases of relief.

Come to find out, this is not the first time you Mac Rust has been caught in a con. In May of last year, the Securities and Exchange Commission sued Mr. Rust for “misappropriat[ing] significant portions of funds [approximately $13.8 million] entrusted to” Rust and Christoper Brenner and that Rust and Brenner “commandeered the remainder for their own undisclosed trading in speculative securities derivatives. Mac Rust’s Texas State Bar License is now “inactive,” although no public disciplinary history is listed.

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. 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.

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. This experiment is about applying Cocoa and Rust knowledge to create something safe and yet easy to work with.

Getting started with Cocoa crates

Rust For Mac

There are already crates for working with the Objective-C runtime, such as the [CODE]objc[/CODE] and [CODE]block[/CODE] crates, which are for using the runtime directly and interfacing with Apple’s block extensions respectively. The [CODE]objc[/CODE] crate in particular provides the [CODE]msg_send![/CODE] macro, which is a basic interface to messaging Objective-C objects. Here’s an example of creating an [CODE]NSObject[/CODE]:

-- CODE language-rust --
unsafe {
let cls = Class::get('NSObject').unwrap();
let obj: *mut Object = msg_send![cls, new];
}

The [CODE]cocoa[/CODE] crate builds on this to provide an interface to using frameworks including AppKit for drawing windows and views onscreen. It also has an interesting take on implementing Objective-C classes in that translates them to traits which are implemented by a generic [CODE]NSObject[/CODE] type. This snippet creates an app and a window, and presents it on screen:

-- CODE language-rust --
unsafe {
let _pool = NSAutoreleasePool::new(nil);
let app = NSApp();
app.setActivationPolicy_(NSApplicationActivationPolicyRegular);
let window = NSWindow::alloc(nil).initWithContentRect_styleMask_backing_defer_(
NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)),
NSTitledWindowMask as NSUInteger,
NSBackingStoreBuffered,
NO
).autorelease();
let title = NSString::alloc(nil).init_str('Hello World!');
window.setTitle_(title);
window.makeKeyAndOrderFront_(nil);
app.run();
}

Pretty cool, though as is, the entire interface is unsafe, missing the hopeful goal of the experiment. This approach could still be interesting when writing the application core code in Rust, and then packaging it using Cocoa bindings.

Wrapping Cocoa APIs in “safety”

Rust For Mac

Given those caveats, couldn’t we create Rust wrappers for Objective-C classes? Of course! After some trial and error, I had a base trait to use for wrapping and interacting with Objective-C objects:

-- CODE language-rust --
use objc::runtime::Object;
pub type Id = *mut Object;
pub trait ObjCClass: Sized {
/// Returns pointer to underlying objc object
fn ptr(&self) -> Id;
/// Creates an instance from an objc object pointer, failing
/// if the pointer is not an instance of the wrapped class
fn from_ptr(ptr: Id) -> Option<self>;</self>
/// The printed name of the class
fn class_name() -> &'static str;
/// Type-safe reference to an instance with a nil pointer
fn nil() -> Self;
/// Performs an `isKindOfClass` check to whether a particular
/// pointer is an instance of the wrapped class
fn ptr_is_class(ptr: Id) -> bool;
/// Change an instance of one class into another, failing if
/// the pointer is not an instance of the preferred class.
/// Useful for converting between inherited classes e.g.
/// NSDictionary to NSMutableDictionary.
fn coerce<t: objcclass='>(&self) -> Option<t> {</t></t:>
T::from_ptr(self.ptr())
}
/// Designate this instance as suitable for being released
/// once it is out of scope
fn autorelease(&self) -> Self;
/// Drop the Objective-C reference. The object is then invalid
fn release(&mut self);
}

Note that this creates a Rust object with a reference to an Objective-C object, but the overall effect is minimal as most interaction still happens in Objective-C runtime land.

Using this trait was most easily done creating a handy macro named [CODE]impl_objc_class[/CODE], and then wrapping the average class became easy! Here’s an example which wraps a few methods on [CODE]NSString[/CODE].

-- CODE language-rust --
const UTF8_ENCODING: NSUInteger = 4;
impl_objc_class!(NSString);
impl NSString {
/// Creates an `NSString` from a `str`.
pub fn from(content: &str) -> Self {
let ptr: *mut Object = unsafe {
let string: *mut Object = msg_send![class!('NSString'), alloc];
msg_send![string, initWithBytes:content.as_ptr()
length:content.len()
encoding:UTF8_ENCODING]
};
NSString { ptr: ptr }
}
/// The length of the string as measured in UTF-8 code points
pub fn len(&self) -> usize {
unsafe { msg_send![self.ptr, lengthOfBytesUsingEncoding:UTF8_ENCODING] }
}
}

The class can now be used directly, and without [CODE]unsafe[/CODE]:

-- CODE language-rust --
let greeting = NSString::from('hello');
assert_eq!(greeting.len(), 5);

Resources still need to be released (or auto-released, if applicable) when they are no longer needed, but classes became much easier to use. I explored some options such as implementing a [CODE]Drop[/CODE] 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.

Packaging Rust into an app

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 [CODE]mailto:[/CODE] links, for example). For that, we’d need to package the executable into an app bundle.

An easy way to create an app bundle which launches Rust code is to create a Cocoa app with a Rust and dependent app target. This requires a few steps in Xcode:

For
  • Create a new app using the Cocoa app template
  • Add a second “External build system” target to the application which creates the Rust binary
  • Add the second target to the default app target as a dependency
  • Add the rust executable as a bundled resource of the app target
  • Replace the default AppDelegate with a script to launch the Rust binary, something like this bit of Swift:
-- CODE language-rust --
let task = Process()
task.launchPath = Bundle.main.path(forResource: 'my-rust-program', ofType: nil)
task.launch()
task.waitUntilExit()

I’ve created an example which shows all of these parts in action, adds an app icon, and pipes output from the Rust executable to the system console.

Conclusions

The initial results were less than ergonomic when using the existing Cocoa crate since the interface did not add additional safety, and perhaps removed some because the generic object type conformed to every Cocoa class trait. I could (and did) call the wrong methods on Cocoa class instances.

Writing my own layer of classes on top of [CODE]objc[/CODE] improved the latter, though it was more initial overhead to write wrappers before using classes, and still felt clumsy when converting between values in class clusters for example. There is potential for a “Rustier” crate for interfacing with Objective-C, or a generator which makes ergonomic method names. Despite this, I mapped a number of Objective-C classes by hand, and while my stylistic choices probably aren’t suitable for a general use library, Rust+Cocoa became very fast to use and iterate on ideas. The approach could be worth a try if you have reusable components in Rust to share with a Cocoa application, and have constructs unsuitable for use with the foreign function interface.

There’s more I could cover here about the experience, like how to declare your own Objective-C classes in Rust and implementing protocols, but that should be the topic of a later post.

Rust On Mac Os

I’ve made some longer examples demonstrating the snippets in this post as well as a general template usable for packaging a mac app, which is available on GitHub.

Rust For Macos

Thanks for reading!