Hello Rustacean! Welcome to another edition of the Rust Bytes newsletter. In this issue, we'll shine a spotlight on an amazing Rust project, present our spot-the-bug challenge, and share some incredible links of the week.
Welcome to Issue 17!
The Main Thing
RustPython is a Python interpreter written in Rust. RustPython can be embedded into Rust programs to use Python as a scripting language for your application, or it can be compiled to WebAssembly in order to run Python in the browser. RustPython is free and open-source under the MIT license.
RustPython is in development, and while the interpreter certainly can be used in interesting use cases like running Python in WASM, RustPython is not fully production-ready.
RustPython’s goals include:
Fast, reliable and secure implementation of Python that can be used from Rust or compiled to WebAssembly.
Full Python 3 environment entirely in Rust (not CPython bindings), with a clean implementation and no compatiblity hacks.
RustPython is already used in a few projects:
GreptimeDB: an open-source, cloud-native, distributed time-series database. Using RustPython for embedded scripting.
pyckitup: a game engine written in rust.
Robot Rumble: an arena-based AI competition platform
Ruff: an extremely fast Python linter, written in Rust
RustPython is available here.
Rust Pun
Why do Rustaceans love to cook?
Because they're great at managing recipes with lifetimes!
Spot the Bug
Ownership + Move + Borrow.
Identify why the code fails to compile and suggest a way to fix it.
Share your solution in the comments below for a chance to be featured in our next newsletter!
Project Spotlight
Nushell
Nushell is a new type of shell written in Rust.
Features
Nushell works on Linux, macOS, BSD, and Windows.
Nushell pipelines use structured data so you can safely select, filter, and sort the same way every time.
It's easy to extend Nushell using a powerful plugin system.
Nushell speaks JSON, YAML, SQLite, Excel, and more out of the box.
Nushell operates on typed data, so it catches bugs that other shells don't. And when things break, it tells you exactly where and why.
Nushell is open-source on Github.
Awesome links of the week
This article, titled "It's a library AND a binary" and written by Gankra, explores a clever technique in Rust where a single Cargo package can function as both a library and a standalone application.
John Nunley explains the internal of async-task crate. Read it here.
The OpenAPI specification (OAS) defines a standard, language-agnostic interface to HTTP APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code. Joshua Mo explains different ways of using OpenAPI in a Rust context. Read more here.
Rustls is a modern Transport Layer Security (TLS) library written in Rust, with the aim of replacing non-memory safe alternatives such as OpenSSL. Read about the Rustls journey of continuous benchmarking.
Take a look at how Meilisearch implemented incremental indexing in Arroy. This is a four part blog series. The blogs are: Part1, Part2, Part3 and Part4.
Read the ideas shared by llogiq on how to learn as little Rust as possible to become productive in Rust, so you can start and have success right away and learn the harder parts later when you’re comfortable with the basics.
Bo Lin, Alexander Bogdanowicz, and Lukas Schulte share their experience of using Rust in building a SQL compiler, semantic analyzer, and data build system in their blog Fast Development In Rust, Part Two.
Read the article by Roman Kashitsyn on implementing domain types effectively. The article uses Rust like syntax but the ideas can easily translate to any statically typed language.
octox is a Unix-like Operating System completely implemented in Rust from scratch. Learn how the features of Rust are utilized in its implementation. Read it here.
Take a look at the video by Naz to understand testing in Rust.
Spot The Bug: Solution
The Bug: Compiler error!
Solution:
`marks` has type `Vec<i32>`, which does not implement the `Copy` trait. This vector is moved in the for-loop due to an implicit call to `.into_iter()`. Another way of saying this is, the for-loop takes the ownership of the vector.
The `println!` tries to use the vector after it is already moved. So, the compiler gives the error: "value borrowed in `println!` after move".
To solve the error we need to use a shared reference to the vector in the for-loop.
```
fn main() {
let marks = vec![10, 9, 8, 4, 6];
let mut sum = 0;
for mark in &marks {
sum = sum + mark;
}
println!("Sum of all marks {:?} is {}", marks, sum)
}
```
Before You Go
To support the newsletter:
❤️ Recommend the newsletter to your friends: it really helps!
💸 Sponsor the newsletter
🤳 Check us out on our socials: X, Rustaceans Publication.
📨 Contact us through rustaceanseditors@gmail.com feedback is welcome
That's all for now, Rustaceans! Until next week, have a productive week ahead.