wiki:Languages/Rust

Rust

An effort to create community-driven systems programming language. It is an Implementation Language, so know why you do what you do first. It is already a much better language than C++. But feels Rubyish due to a syntax clutter and lack of uniformity, like in ML or Haskell.

It is much less minimalistic, disciplined, uniform and less polished than Standard ML or even Go. It is much more like Ruby (compared to Python which is a high-skilled and principle-guided community effort), than PHP (a crowded bazaar of ignorant amateurs).

What is absolutely wonderful is that Rust is focused on Structures and Traits instead of classes, the way very smart oldtimers did with Common Lisp or PLOT3.

It has Sum types as Enums, so algebraic data types are there

Unfortunatyly, its pattern-matching is limited to a match expression only, instead of being uniform as in Standard ML or Haskell.

No objects. No classes

It has a few fundamental concepts out of which programs should be build:

  • Structures (values)
  • Functions
  • Traits (composable Interfaces)

No objects, no classes, only values and only composition. This is a right approach.

Immutability by default

All mutations must be explicitly marked, so they are available to the type checker.

mv instead of ln or cp

  • A variable is dropped when a scope is exhausted (got out of scope).
  • Implicit (automatic) RAII based on a Lexical Scoping rules.

Values are moved between variables (box-like containers) instead of being linked (referenced) or copied.

Copyable or Movable

  • A type is Copyable if it implements the Copy trait.
  • A type is Moveable if it implements the Drop trait.

Passing a variable to a function will move or copy, just as ordinary assignment does.

  • assigning a value to another variable moves it.
  • returning a value of a Moveable type transfers ownership.

References

&x is a reference to variable (a box) x (a pointer to x, an address which is merely an offset)

Only immutable aliasing

  • At any given time, you can have either one mutable reference or any number of immutable references.
  • only one mutable reference (&mut x) to a particular piece of data (a box-like variable) in a particular scope.

Mutable reference is basically an mvar of functional languages - a value wrapped into a closure.

Borrow checker

Code written so that each invocation only modifies what it owns is almost as good as purely functional code.

Rust compiler tracs a life cycle of each mutable variable, including when it left the scope - being passed to (or borrowed by) another procedure.

This makes an imperative language memory-safe, which means, that wrong code (like accessing a variable after it left the scope) will not compile.

Tooling

Language Server

$ cargo install --force racer
$ cargo install --force rustfmt # optional

Emacs

(package-install 'lsp-mode)
(package-install 'lsp-ui)
(package-install 'lsp-rust)
(package-install 'rust-mode)

Neovim

git clone git://github.com/rust-lang/rust.vim
git clone git://github.com/autozimu/LanguageClient-neovim.git
cd LanguageClient-neovim
cargo install --force
Last modified 10 months ago Last modified on Dec 6, 2018, 5:53:10 AM
Note: See TracWiki for help on using the wiki.