Get the latest tech news

An Optimization That's Impossible in Rust


In this article, I'll describe how I implemented German string and the challenges of doing so in Rust. Specifically, I'll examine how to enable shared ownership for such data structure. Providing unique ownership is relatively trivial, and there is already a nicely written tutorial from the Rustonomicon teaching you how to [implement a `Vec`], which is not much different from a `String`. But first, let's talk about the concept of German string.

by xkcd licensed under CC BY-NC 2.5 In this article, I’ll describe how I implemented German string and the challenges of doing so in Rust. Providing unique ownership is relatively trivial, and there is already a nicely written tutorial from the Rustonomicon teaching you how to implement a Vec<T>, which is not much different from a String. A better approach is as follows, without relying on such an invariant and freeing us from worrying about field orders when providing structs for different ownership strategies for the allocated buffer.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Rust

Rust

Photo of optimization

optimization

Related news:

News photo

Raspberry Pi Showcases Rust On The RP2350 Microcontroller

News photo

Google says replacing C/C++ in firmware with Rust is easy

News photo

Creating an empty iterator of a certain type in Rust (2018)