Do you remember the time when
one developer broke half of the Internet?
Earlier this year a package called
left-pad
was pulled from the NPM
registry (a counterpart of crates.io for the JavaScript folks). This caused...
some drama, to say the least. Shall we try this in Rust? Not sure about the
drama, maybe just padding a string on the left is enough. There's a crate for
that - leftpad
!
Czytaj dalej »
If you have a background in Python, Java or C++, you're probably used to
raising exceptions if something goes wrong. Rust doesn't have exceptions.
The official Rust book has a
comprehensive chapter on error handling,
but the TL;DR is we should probably use the Result
type. We can match
on its variants to handle both the happy path and error cases in a very
explicit, if not verbose, way. To address the verbosity, there was a try!
macro that cut down on a lot of pattern matching boilerplate. And as of now
we have an even simpler syntax - the ?
operator. But when there are many
error types, possibly coming from different libraries, making them compose well
still requires a lot of code: From
and Error
implementations and such.
The error_chain
crate was created
to avoid all that remaining boilerplate. Let's see it in action!
Czytaj dalej »
diesel
is an in-development ORM (Object-Relational
Mapper) for Rust. It aims to be a safe and efficient layer between your
business logic and the database. In the words of its authors:
Diesel gets rid of the boilerplate for database interaction and eliminates
runtime errors, without sacrificing performance. It takes full advantage
of Rust's type system to create a low overhead query builder that
"feels like Rust".
The primary author of diesel
- Sean Griffin -
is also a Ruby on Rails committer and maintainer of Active Record, the ORM used
in Rails. So when I saw his name in relation to a Rust ORM, I knew I have
to check it out. Sean also gave a great talk at
PolyConf 16 about ownership semantics (not only in
Rust) - Owning Ownership.
Czytaj dalej »
Most of software developers are to some extent familar with
Git. This version control system won our hearts
even though it is not perfect. Practicality beats purity, as quoted
from The Zen of Python.
But Git is not only the git
executable. It's the entire ecosystem around
Git that made it so successful - IDE integrations, hosting services and
third-party tools and libraries. One of these is a very popular C library called
libgit2
which implements Git APIs (although
git
itself doesn't use libgit2
and
probably never will).
There are bindings to libgit2
in many languages, but we're interested
primarily in Rust, right? The git2
crate
provides safe Rust bindings.
Czytaj dalej »
tera
is a pure Rust templating engine.
Those familiar with Django,
Jinja2 or Twig
will feel right at home with tera
, as its syntax is very similar.
tera
is still very young and may not be as feature complete as, say, Jinja2.
However it is actively developed and the maintainer is very open to new
contributions, so feel free to
tackle some issues!
Czytaj dalej »