←back to thread

Introducing tmux-rs

(richardscollin.github.io)
857 points Jtsummers | 3 comments | | HN request time: 0.896s | source
Show context
mbreese ◴[] No.44455951[source]
> You might be asking: why did you rewrite tmux in Rust? And yeah, I don’t really have a good reason. It’s a hobby project. Like gardening, but with more segfaults.

I love this attitude. We don’t necessarily need a reason to build new things. Who knows what will come out of a hobby project. Thanks to the author for the great write up!

Also, my gardening is full of segfaults, coding a new project is definitely safer to my yard.

replies(15): >>44456003 #>>44456205 #>>44456799 #>>44457023 #>>44457048 #>>44457108 #>>44457783 #>>44458165 #>>44458298 #>>44458461 #>>44459018 #>>44459396 #>>44459476 #>>44459885 #>>44463066 #
cultofmetatron ◴[] No.44456799[source]
> Like gardening, but with more segfaults.

interesting, I'm new to rust. what are you doing that necessitates using unsafe?

replies(2): >>44456889 #>>44457183 #
jeroenhd ◴[] No.44457183[source]
A lot of things that C will let you do (even if you enter the realm of undefined behaviour) will simply not compile to C. As the author states, there are semantic differences between pointers and Rust's references.

C pointers can have as many owners as you want, may be subjected to mathematical operations, and can be cast to any type without even an error message. The compiler will just assume you know what you're doing. If you enable enough compiler warnings, it might warn you, but C compilers don't generate a lot of those by default.

Rust will let you only generate one mutable (exclusive) reference at a time. This means straight C to Rust ports simply don't compile.

By switching to pointers, which work pretty much like their C equivalent, you can port the code much easier, but you do of course lose the benefits of Rust's safety mechanisms, because most pointer operations throw away all the safety guarantee that Rust provides.

replies(3): >>44457388 #>>44459258 #>>44459618 #
SoftTalker ◴[] No.44457388[source]
So what is the advantage of an unsafe Rust implementation? Just to have done it?
replies(5): >>44457474 #>>44457712 #>>44458531 #>>44458900 #>>44459852 #
1. petrzjunior ◴[] No.44457712[source]
It is rewritten to a different language and many people find Rust easier to read, it has better type hint support for IDE etc. Also, you do not lose all the safety, there are still many rules enforced, such as safe linking, no undefined functions. Unsafe Rust means that all parts of code which do illegal pointer magic are explicitly marked with an "unsafe" keyword. You can now go one by one and fix them.
replies(1): >>44463506 #
2. techbrovanguard ◴[] No.44464127[source]
> chuckles

jesus christ, you’re not light yagami—please stay on /g/

replies(2): >>44464177 #>>44474167 #
3. johnisgood ◴[] No.44474167{3}[source]
Someone is going on a witch-hunt. Most of my comments under this submission are flagged, including this one: https://news.ycombinator.com/item?id=44464177.

Crazy. They have gotten quite a lot of upvotes, for the record, but feel free to flag ALL of my comments.

I wonder what is so wrong about asking if I cannot chuckle anymore, so wrong that it warrants it to be flagged.

>> chuckles (written by me)

> jesus christ, you’re not light yagami—please stay on /g/ (written by some individual)

However, is not flagged. It would be hilarious if it was not so sad.