Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From the article:

> But wait, how is that possible? We can’t both allow and disallow mutable state. What gives?

I had to re-read the above a few times. And still don't get it. Steve, what do you mean with it? Are you talking about how are Arc/RWArc implemented? Or is it something else?



The previous sentence is "We gain the efficiency of shared mutable state, while retaining the safety of disallowing shared mutable state."

I also wasn't sure about the part you quoted, but I was trying to explain that it's not that Rust _doesn't_ allow shared mutable state, it's that while the language doesn't, you can use unsafe to build safe abstractions, so in practice, it does. Hmmm.


I still don't get it... And the previous sentence is now confusing for me too :)

First you showed two examples: Arc (to share immutable data) and RWArc (to share mutable data with enforced mutexes around closures). Then you talked about `unsafe`. Seems easy, one needs a "backdoor" to implement RWArc in Rust (at first I thought it was implemented in C/C++).

But (quoted) sentences between Arc/RWArc part and `unsafe` part don't really connect them, at least to me.


Ha! Bummer, maybe I will just need to re-write this paragraph.

A RWArc is shared mutable state: you can have two references to the Arc in two different tasks. Yet I said that Rust throws a compiler error for shared mutable state.

> (at first I thought it was implemented in C/C++).

There's very little C++ in Rust anymore. :)

> Seems easy, one needs a "backdoor" to implement RWArc in Rust

Yup, this is exactly the point with those two sentences. Maybe I should just straight-up remove them.


> There's very little C++ in Rust anymore.

I think we've now got none, except for LLVM in the compiler, which means any binaries built using the stdlib don't need any C++ libraries (to be clear, libraries without the stdlib have never needed any).


> Maybe I should just straight-up remove them.

Or be explicit that you'll now talk about RWArc implementation.


Yes. This.

I found it a bit worrying, as when I read that I had to go back and re-read the code a few times to make sure that there wasn't an unsafe block in the code, or perhaps that the use of RWArc implied unsafe, and would then turn that whole function into an automatically unsafe block.

Nevertheless, very cool. I really liked the tutorial, I'm getting quite excited by Rust.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: