
Deep Atlantic Storage: Rewriting in Rust
<blockquote> <p>This post is originally published on yoursunny.com blog <a href="https://yoursunny.com/t/2026/das-rust/" rel="noopener noreferrer">https://yoursunny.com/t/2026/das-rust/</a></p> </blockquote> <p>I have been coding in <a href="https://your
Junxiao Shi Posted on May 25 • Originally published at yoursunny.com Deep Atlantic Storage: Rewriting in Rust # rust Deep Atlantic Storage (4 Part Series) 1 Deep Atlantic Storage: Sorting Bits 2 Deep Atlantic Storage: Reading File Upload in Web Workers 3 Deep Atlantic Storage: Streaming Bits 4 Deep Atlantic Storage: Rewriting in Rust This post is originally published on yoursunny.com blog https://yoursunny.com/t/2026/das-rust/ I have been coding in C++ , Go , and TypeScript for many years, but recently I started learning the Rust Programming Language . Why Rust I choose to study the Rust programming language because: Rust is one of the major system languages that I do not know. Rust, just like Go, is a memory safe language, apparently now a national security issue . Rust, unlike Go, does not have a garbage collector. Rust, unlike Go, does not have a nil pointer. The last point is particularly important. In Go, I often find myself writing a method with pointer receiver: type Counter struct { V int } func ( cnt * Counter ) Increment () { cnt . V += 1 } Enter fullscreen mode Exit fullscreen mode The pointer receiver is required, if the method needs to modify a field on its receiver. However, more often than not, I forget to check whether the receiver itself is a nil pointer, even in production code . If the above function was called like this: var cnt * Counter cnt . Increment () Enter fullscreen mode Exit fullscreen mode It would experience a panic at runtime : panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x46f383] Enter fullscreen mode Exit fullscreen mode In contrast, Rust's rigid rules can prevent writing such careless code. A function/method is allowed to modify its arguments, including self , only if the argument is passed as a mutable borrow , signified with the mut keyword. Moreover, a borrow can only be created from a real value, allocated in either the stack or the heap. It is generally impossible to have a nil or NULL pointer, or a borrow that points to invalid memory. This different, as I perceive, elevates Rust to have a higher level of memory safety. The Book The official Learn Rust webpage gives three options: The Rust Programming Language, "the book" that covers the language principles and some small exercises. Rust By Examples, a bunch of code with minimal explanation. Rustlings, an interactive tutorial of the Rust syntax in my environment. Two decades ago, I learned HTML and CSS from the official W3C specifications. While I would not go as deep as learning from the language and compiler specifications, I chose the deepest option among the three, "the book" . During the 43-day government shutdown , I studied the book on each weekday. I setup my local environment, pasted the sample snippets, and made small changes to see what would happen. I feel that, Rust is a difficult language to learn. Not in a university taking programming class, I don'
📰Originally published at dev.to
Staff Writer