## Could Mozilla's Rust be a hybrid language bridging C# and F# features?

I've had my eye on this new-ish language being developed by Mozilla called "Rust" , it's coming up to its 1.0 release pretty soon (At time of writing the last release was v0.9 ~ January 2014)

Image courtesy of wikipedia.

From reviewing the high level summary along with observing the immediately noticeable C like syntax, it also shares many features with C#, namely:

no null or dangling pointers, no buffer overflows, optional task-local garbage collection and safe pointer types.

however it also lends some ideas from F#:

variables are immutable by default (but can be overridden), types do no have to be declared explicitly and can be inferred using the let keyword, and with that inference ability comes the strong pattern matching capabilities that F# is known for.

Similar to in C (however contrasting that you do not have to use the "unsafe" keyword) you can use operators for lower level manipulation such as pointers. So all the power of C when necessary with the high level luxury of C# and F#.

#### Other interesting features however that are nice in the language

Mutability can be temporal, via something called "Freezing", for example

let mut money = 10;
// So the variable money is currently mutable,
// however in its usage we can then "freeze" it, using & operator
payment = &money;
// This means that money is now frozen and cannot be modified or reassigned


From the documentation it is currently not concrete to me how long the "freezing" lasts but most likely until the variable referencing it is garbage collected.

Similar to the concept of value types and reference types in C#, you can declare the size of an object to be a heap ptr effectively using the tilda operator (~). This is useful for dynamic memory allocation, they call the notion an owned box, and it is only the size of the heap pointer, same as a reference type in C#.

These follow on to the concepts of vectors and slices, and there are 3 variants as I see it. Static vectors ~ These are just fixed size, dynamic vectors: these are prefixed with the ~ operator allowing the vector to be a reference type/owned box. You can then also have the notion of a "slice" which is effectively a read only view into a contiguous block of memory, view being the keyword there as there is no ownership.

The other things you come to expect in HLL languages are also present such as closures, static methods (functions), instance methods (methods), generics and generic constraints (referred to in rust as "traits" and in earlier versions "kinds"). I like the word trait in preference of constraint (and definitely in preference to kinds as that is a terrible name!). Its like seeing it from a different perspective, we are trying to understand distinguishing features of the generic type, not its limitations.

The built in traits are "Send" - A type has a send trait if basically there are no heap reference via managed/owned boxes or closures. "Freeze" - these are constant immutable types, as discussed above. "Static" - A type that does not contain any references, familiar concept in C# of a static class.

I don't plan to cover all the non-code functionality such as packaging, references and usings (crates, names, files, modules) in this post.

#### Closing notes

An observable key difference however is choice for AOT (Ahead-Of-Time) compilation instead of the more popular JIT (Just-In-Time) compilation, meaning that it won't be as platform agnostic as those other HLL languages running in a virtual machine e.g C# and Java. But it should have the performance and size optimization gains of not having to compile to an intermediate form. However I'm not sure at this point where its usage of LLVM (Low-Level-Virtual-Machine) comes in, it may playout that its compiled to and intermediate form that is then interpreted by LLVM. Don't know the full details on that yet.

As a long time C# developer and part-time F# tinkerer, I'm really pleased with what Rust has to offer. Now to try a project with it!