Ferris the crab mascot - Image courtesy of tweedegolf.nl
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 13!
The Main Thing
Lapce is a lightning-fast and powerful code editor written in Rust. The features include:
Built-in LSP (Language Server Protocol) support to give intelligent code features such as: completion, diagnostics and code actions
Modal editing support as first class citizen (Vim-like, and toggleable)
Built-in remote development support inspired by VSCode Remote Development. Enjoy the benefits of a "local" experience, and seamlessly gain the full power of a remote system.
Plugins can be written in programming languages that can compile to the WASI format (C, Rust, AssemblyScript)
Built-in terminal, so that once can execute commands in your workspace, without leaving Lapce.
The project is open-source on GitHub.
Rust Pun
I once saw a programmer wearing a Rust T-shirt that said
"I'm not afraid of memory leaks, I'm afraid of null pointers."
Spot the Bug
The Curious Case of the ownership.
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
Tokio
Tokio is a runtime for writing reliable, asynchronous, and slim applications with the Rust programming language. It is:
Fast: Tokio's zero-cost abstractions give bare-metal performance.
Reliable: Tokio leverages Rust's ownership, type system, and concurrency model to reduce bugs and ensure thread safety.
Scalable: Tokio has a minimal footprint, and handles backpressure and cancellation naturally.
The project is open-source on GitHub.
Awesome links of the week
Stefan Baumgartner explains Async Rust in the article Async Rust in a Nutshell.
WebAssembly is a type of code that can be run in modern web browsers. Learn how to write WebAssembly module in Rust in Joshua Mo’s article.
Lapce is a native Open-Source code editor written in Rust and supports remote development. Sergio De Simone shares some features of Lapce in his article.
RustConf 2024, the call for talk proposals is open.
Clippy deprecates `feature = "cargo-clippy"`. Read about the motivation for deprecation here.
Read about Nicholas Nethercote’s experiences of code reviews in Rust compiler team here.
"Writing a scheduler for Linux in Rust that runs in user-space", the arighi's blog evolves the idea of a fully-functional Linux scheduler written in Rust that runs in user space (Part 1) into a generic framework that allows implementing any scheduling policy in user-space, using Rust.
Understand JetBrains’ investment in Rust through a discussion between Vitaly Bragilevsky, Developer Advocate at JetBrains, and Luca Palmieri, Principal Engineering Consultant at Mainmatter.
thread_local crate provides the ThreadLocal type which allows a separate copy of an object to be used for each thread. It also allows iteration over the thread-local values of all thread. Is thread_local expensive?
Ludi Rehak explains three things that one can do in Rust but not in Golang. Check it out here.
Spot The Bug: Solution
Explanation:
The Bug: Compiler error!
The spawn method is generic over two parameters F and T, where the generic parameter F defines the input type and T defines the return type. We will focus on the type parameter F, it is a closure that can be executed once and returns a result of type T.
pub fn spawn<F, T>(f: F) -> JoinHandle<T>
where
F: FnOnce() -> T,
F: Send + 'static,
T: Send + 'static,
{
.....
}
Look at the lifetime of the input parameter type, it is 'static,
F: Send + 'static.
This means F and any variables captured by F may outlive the function in which the spawn method is invoked. Hence, any variables captured by F should be owned by F.
Solution:
The main function needs to give away the ownership of the vector (numbers) by using the "move" keyword alongside the closure (in the invocation of spawn method).
fn main() {
let numbers = vec![1,2,3,4];
let handle: JoinHandle<i32> = thread::spawn(move || {
return numbers.iter().sum();
});
let sum = handle.join().unwrap();
println!("sum of numbers = {}", 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.