20 ms·
I've followed rust for a couple years, never done anything major with it. It doesn't have coroutines, but they might be possible to implement using a macro tha
by adrusi 12y ago
I've followed rust for a couple years, never done anything major with it.
It doesn't have coroutines, but they might be possible to implement using a macro that expands to an iterator implementation. It also has go-like channels and can be used with both N:M (green) threads and os-native 1:1 threads. It handles streams of data quite well.
All variables and references in Rust are immutable by default and accessing global mutable state can only be done in explicitly marked unsafe code. I think that all functions that have no "mut" or "unsafe" in their signature are pure unless they use an "unsafe" block. Exposing unsafe behavior in a safe interface is a contract violation and considered a bug.
There's no built in laziness, but because Rust allows for overloading the pointer dereference operator, it should be possible to implement thunks in a syntactically transparent way.
Rust has a full macro system. There are AST-based macros for when you need a serious amount of power, but most macros are implemented on a partially structured token stream and are implemented a lot like scheme's syntax-case. It's a lot cleaner than metaprogramming in dynamic languages like python and ruby IMO, and it has no runtime overhead.
Introspection? No, but I think doing something about that is on the post-1.0 roadmap.
Garbage collection. A reference-counted pointer like C++11's shared_ptr is available in the standard library. Its use is discouraged, though, in favor of structuring your code to work with Rust's lifetime system and borrow checker. Doing that, your memory is managed in a safe way with no runtime overhead, you don't have to worry about reference cycles, and the structure it enforces in your code tends to be easier to follow (although often harder to come up with).
Rust isn't really meant to be used in place of Scala, it's more of a "competitor" to C++. It keeps C++'s promise of "don't pay for what you don't use" and strongly favors 0-cost abstractions. It differentiates itself from C++ by using more modern abstractions and garaunteeing safety.
- jeremyjh 12y agoI'm not totally clear on the status of green threads but I'm not sure they should be encouraged presently. My understanding is they will be an external package and std::io will not support them. [1]https://github.com/rust-lang/meeting-minutes/blob/master/workweek-2014-08-18/threading-model.md https://github.com/rust-lang/meeting-minutes/blob/master/wor...
- adrusi 12y agoI think that the external package is supposed to work by providing an alternate implementation of std::io and several other parts of the standard library. Green threads will continue to be fully supported, but they are second class.