For a bit more than a year now, I've been interested in RustThe Rust Programming Language – www.rust-lang.org, a programming language by Mozilla research that “runs blazingly fast, prevents nearly all segfaults, and guarantees thread safety.” It is as low-level as C or C++, has a nice type system (with generics and traits), a helpful compiler, and a great package manager called CargoCargo, Rust's Package Manager – doc.crates.io.
Since Rust 1.0Announcing Rust 1.0 – blog.rust-lang.org was released half a year ago (in May 2015), a lot of libraries (“crates”) have been published to Cargo's main public registry crates.ioThe Rust community's crate host – crates.io (including some of mine). Here are some good practices
In Rust, function signatures tell a story. Just from glancing at the signature of a function an experienced Rust user can tell much of the functions behaivor.
In this article we'll explore some signatures and talk about how to read them and extract information from them. While exploring, you can find many great function signature examples in the Rust API docs. You can play around on the Playpen.
This article assumes some knowledge of Rust, glossing over a bit of the book should be quite sufficient if you are lacking that but have programmed before.
If you're used to C++, C, or the other systemsy languages hopefully this should all seem very familiar, despite the syntax differences. Ideally by the end of your article you'll think more about your function signatures as you write them!
Like most programming languages, Rust encourages the programmer to handle errors in a particular way. Generally speaking, error handling is divided into two broad categories: exceptions and return values. Rust opts for return values.
In this article, I intend to provide a comprehensive treatment of how to deal with errors in Rust. More than that, I will attempt to introduce error handling one piece at a time so that you’ll come away with a solid working knowledge of how everything fits together.
When done naively, error handling in Rust can be verbose and annoying. This article will explore those stumbling blocks and demonstrate how to use the standard library to make error handling concise and ergonomic.
This article marks the end of the second edition of 24 days of Rust. I hope you enjoyed it and maybe found inspiration for a project or two. I sure did :-) Some of the libraries I wrote about are familiar to almost entire Rust community. Some are fairly obscure but I find them interesting. Regardless, I learned a lot just by writing, trying to come up with meaningful code examples and editing my drafts. This was my intention all along - to learn something for myself while contributing these articles to the community.
Systems programming languages have come a long way in the 50 years since we started using high-level languages to write operating systems, but two thorny problems in particular have proven difficult to crack:
It’s difficult to write secure code. It’s common for security exploits to leverage bugs in the way C and C++ programs handle memory, and it has been so at least since the Morris virus, the first Internet virus to be carefully analyzed, took advantage of a buffer overflow bug to propagate itself from one machine to the next in 1988.
It’s very difficult to write multithreaded code, which is the only way to exploit the abilities of modern machines. Each new generation of hardware brings us, instead of faster processors, more of them; now even midrange mobile devices have multiple cores. Taking advantage of this entails writing multithreaded code, but even experienced programmers approach that task with caution: concurrency introduces broad new classes of bugs, and can make ordinary bugs much harder to reproduce.
These are the problems Rust was made to address.
Rust is a new systems programming language designed by Mozilla. Like C and C++, Rust gives the developer fine control over the use of memory, and maintains a close relationship between the primitive operations of the language and those of the machines it runs on, helping developers anticipate their code’s costs. Rust shares the ambitions Bjarne Stroustrup articulates for C++ in his paper “Abstraction and the C++ machine model”