background preloader


Facebook Twitter

Rust Tips and Tricks. Rust has been see­ing in­creased adop­tion, both in acad­e­mia and in­dus­try, over the past few months.

Rust Tips and Tricks

This is great news for the lan­guage and its com­mu­nity. How­ever, it in­evitably also means that a num­ber of peo­ple with rel­a­tively lit­tle ex­pe­ri­ence in Rust are ex­posed to Rust code­bases, and, in many cases, are asked to mod­i­fied them. As pro­gram­mers, when we start using a new lan­guage, we often carry over the isms of the lan­guages we al­ready know into our new code. We don’t know how to write id­iomatic code, and don’t know the many con­ve­nient short­cuts the lan­guage pro­vides, but we make do and fid­dle with things until the pro­gram com­piles and runs.

This is per­fectly nat­ural. Re­turn­ing val­ues In Rust, func­tions, con­di­tion­als, matches, and blocks all au­to­mat­i­cally re­turn the value of their last ex­pres­sion. Impl Bar { fn get_baz(&self) -> &str { return self.baz; }} You can use: impl Bar { fn get_baz(&self) -> &str { self.baz }} let words = vec! Or. Rust-101: This is Rust-101, a small tutorial for the Rust language.


It is intended to be an interactive, hands-on course: I believe the only way to really learn a language is to write code in it, so you should be coding during the course. If you have any questions that are not answered here, check out the "Additional Resources" below. In particular, the IRC channel is filled with awesome people willing to help you! I spent lots of time there ;-) I will assume some familiarity with programming, and hence not explain the basic concepts common to most languages. Brson/httptest. Rust Borrow and Lifetimes. Rust is a new programming language under active development toward 1.0.

Rust Borrow and Lifetimes

The Rust programming language. The Rust Programming Language. Welcome!

The Rust Programming Language

This book will teach you about the Rust Programming Language. Rust is a modern systems programming language focusing on safety and speed. It accomplishes these goals by being memory safe without using garbage collection. "The Rust Programming Language" is split into three sections, which you can navigate through the menu on the left. The Periodic Table of Rust Types. This "periodic table" is a cheatsheet for various Rust types.

The Periodic Table of Rust Types

Rust programming language has a versatile type system that avoids a certain class of memory error in the safe context, and consequently has somewhat many types at the first glance. This table organizes them into an orthogonal tabular form, making them easier to understand and reason. This table does not indicate that Rust has a complex type system compared to other languages. Rust does have seemingly many types, but you only need to understand the meaning of each axis, or even just each column. There are some non-trivial but reasonable interactions between rows and columns though, therefore this table strives to illustrate that. The periodic table was made by Kang Seonghoon as a thought experiment, and then... it have got redditted unexpectedly :p Henceforth I've made the URL permanent and added some descriptions. Explore the ownership system in Rust.

This two-part guide is for a reader who knows basic syntax and building blocks of Rust but does not quite grasp how the ownership and borrowing works.

Explore the ownership system in Rust

We will start very simple, and then gradually increase complexity at a slow pace, exploring and discussing every new bit of detail. This guide will assume a very basic familiarity with let, fn, struct, trait and impl constructs. Our goal is to learn how to write a new Rust program and not hit any walls related to ownership or borrowing. In this first, ownership part: After short Introduction we will learn about the Copy Traits, and then about the Immutable and Mutable ownership rules. Prerequisites - What you already know Scope/stack based memory management is quite intuitive, because we are very familiar with it.

What happens to i at the end of the main function? Learning Rust. By Robin G.

Learning Rust

Allen Last updated: 2014-11-02 15:35 UTC Inspired by Artyom's Learning Racket series, I've decided to log my efforts in learning Rust. I'm going to document my learning process as I go about trying to build a roguelike in Rust. I've downloaded the compiler, skimmed the getting started guide, and written “Hello World”. For those following along at home: I started out using Rust 0.11.0 and then later upgraded to 0.13.0. So after successfully getting a “Hello World” compiling, I'll start to turn the program into the beginnings of a roguelike. Quick look at the Rust manual for how to do looping, and let's also separate this stuff into a draw() function: fn draw() { for x in range(0i, 10i) { for y in range(0i, 10i) { print!