Rust

Rust is a programming language designed to be performant, safe, and productive.

Description

combines concepts from C, C++, and Haskell. In order to guarantee type safety and compile to performant machine code, the compiler tracks the type of each variable and function. Where the compiler can not infer a type of a variable, parameter, or result, it must be annotated with a type. In order to guarantee memory safety, the compiler also tracks the lifetime of each variable. Where the compiler can not infer the lifetime of a variable, parameter or result, it must be annotated with a lifetime.

Like Tcl, Rust does not employ a garbage collector, but tracks a value through its lifetime and deallocates the resources for it at the end of its lifetime. For each value, there is always exactly one variable that owns it. Like C, & produces a reference to the value bound to a variable. In Rust this is called borrowing because the compiler does not allow the lifetime of a reference to be longer than the lifetime of the the owning variable. This avoids a whole class of memory errors that C programs are susceptible to. * follows a reference to access the value.

The value bound to a variable is immutable by default, if a variable is annotated with mut, the variable may be used to mutate the bound value. The value boun to a mutable variable may be borrowed, but the compiler ensures that it is never borrowed more than once at any given point during execution. This eliminates data races in Rust programs.

A program is composed primarily of structs and the functions that operate on them. A struct is in turn composed of primitive values, structs, enums, and references to any of those things or to functions. An enum is a type that enumerates any number of possible variants, each of which may be struct. A function that accepts an enum uses match to tailor its operation to each possible variant of the enum.

A group of functions declared as an interface is called a trait. For each type of struct which supports a trait, impl is used to provide a set of function definitions that implement the trait for that type of struct.

Rust features various features for programming the structure of the program itself, i.e. for metaprogramming: A macro language, closures, syntax for templating generic structs and functions, and pattern matching similar to that of Haskell, on language items for such purposes as destructuring variable assignment and code branching according to data type.

Rust is actually segmented into two different languages: safe Rust and unsafe Rust. In the safe parts, nothing is undefined, nothing is null, only safe type conversions are possible, and only safe memory operations are allowed. There is, however, an escape hatch: A function annotated as unsafe takes upon itself the responsibility to guarantee the same things that the Rust compiler guarantees. , so the compiler makes no further effort to check that function for conformance. This makes it possible to write such a function in another language such as C, if needed.