Hacker News new | past | comments | ask | show | jobs | submit login

Box totally implements Send: https://doc.rust-lang.org/std/boxed/struct.Box.html#syntheti...

Also I'm not sure how ? obscures control flow to the same level as C++, which propagates exceptions with no syntactic marker at all.




I preferred the "try!" syntax. The ? is harder to parse visually, harder to find, and makes the language a little more complex (that's one more operator, one more thing to understand, one more thing to parse for tools, etc.)


Well to be fair, I would never advocate using exceptions.

Also I’m quite sure Box doesn’t. I’ve seen compiler errors when attempting to pass one via mpsc.


Your parent’s link says Box implements Send only when it’s T is Send, which makes sense.


I guess? If you’re transferring ownership of something to another thread, that’s perfectly safe. Needing to implement (??) Send for a struct or pod type is cumbersome when it’s something you’d do pretty often.


You don't need to implement Send for POD types – it is automatically implemented. Almost all types implement Send. There are only a few exceptions that I know of: Rc (the non-atomic reference counted pointer) doesn't implement Send because it doesn't support atomically updating the count. Also raw pointers don't implement Send.


The fact that we’re even having this conversation, caused by compiler error ambiguity, demonstrates my point about ergonomics nicely :)


Given that Send is autoimplemented for things that should be Send, this is a strong indication towards your code attempting to send actually not-thread-safe things across threads (things containing borrowed references or Rc<T>)

The error message does drill down and tell you the actual type causing the lack of Send impl.

The only time you have to manually impl Send is for custom container types that are built from raw primitives.


Please file bugs if the errors are confusing!


Eh, they’re probably fine for regular users. They are just nonsensical when you’re starting out.


We care just as much for people just starting out as we do for regular users; possibly even more!


Well, there's plenty to say about C++ compiler errors too!


Clang has done a really amazing job of cleaning those up. I find them super helpful these days.


If you want compiler ambiguity in C++ look no further than Templates... C++ is rarely ergonomic to use.


I like templates, because to date there is not a popular language that can do compile time stuff it can do. And no joke, some of the stuff you can do is quite amazing.


Good thing Send is implemented automatically for types based on their contents, then.

If you're trying to send a value to another thread, Rust will only stop you if the author of some type somewhere inside it has opted out, and none of its containers ever opted back in (as Box does).


It's something you should almost never need to do and about half the manual implementations I see of Send are wrong. Trust Rust on this one.




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

Search: