Earlier quoted context omitted.
> the borrow checker, I do conceptually understand lifetimes, but actually using them is tricky. I've been using Rust for a little over year, almost daily at work, and for several projects. I have a pretty good intuition about how the borrow checker works and what needs to be done to appease it. That said, I don't think I'm any closer to understanding lifetimes. I know conceptually how they are supposed to work (I ne…
I've been writing Rust code since before the 1.0 days, and I still can't understand lifetimes in practice. When the compiler starts complaining about lifetimes issues, I tend to make everything clone()able (either using Rc, or Arc, or Arc+Mutex, or full clones). Because if you start introducing explicit lifetimes somewhere, these changes are going to cascade, and tons of annotations will need to be added to everythin…
Rust 1.46
91–100 of 157 posts
Re: Rust 1.46
#92Earlier quoted context omitted.
I've been writing Rust code since before the 1.0 days, and I still can't understand lifetimes in practice. When the compiler starts complaining about lifetimes issues, I tend to make everything clone()able (either using Rc, or Arc, or Arc+Mutex, or full clones). Because if you start introducing explicit lifetimes somewhere, these changes are going to cascade, and tons of annotations will need to be added to everythin…
I think you're really intended to do the latter rather than the former. I mean, Rust lets you do either–it gives you the choice if performance isn't your concern–but usually it's better to not clone everything.
Re: Rust 1.46
#93Earlier quoted context omitted.
> how many function types does Rust have again? Three?). Depending on what you meant, there are more than three: * There are 3 traits, used by closures depending on their needs: * Fn(Args) -> Output * FnMut(Args) -> Output * FnOnce(Args) -> Output * *Every* `fn` is its own type (`fn() {foo}`) * Function pointers (`fn()`), which is how you pass the above around in practice > Rust is very much procedural. I think this…
I realized after I wrote the comment that I was really referring to the closure traits when I said that. And I really should have said "kind" instead of "type" because, like you said, every different function has its own type . But anyway, I don't really disagree with your point about categorizing languages as OOP, Procedural, or Functional. But honestly, in this case, I think it's pretty damn clear than Rust is proc…
I'm not totally sure if this is what you mean, but FYI you can borrow multiple fields mutably using destructuring:
struct Foo(u8, u8);
fn main() {
let mut bar = Foo(1, 2);
let Foo(ref mut x, ref mut y) = &mut bar;
*x += 1;
*y -= 1;
println!("{} {}", bar.x, bar.y);
}Re: Rust 1.46
#94Re: Rust 1.46
#95Is there a resource that explains what const functions are and why you would use them?
Re: Rust 1.46
#96I’m learning rust right now and there is a lot to like. Steady updates like this are also very motivating. The ecosystem feels very sane - especially compared to npm. Top notch Wasm support, cross compiling is a breeze. That said, coming from a FP background (mostly Haskell/JS, now TS) Rust is... hard. I do understand the basic rules of the borrow checker, I do conceptually understand lifetimes, but actually using th…
Re: Rust 1.46
#97I’m learning rust right now and there is a lot to like. Steady updates like this are also very motivating. The ecosystem feels very sane - especially compared to npm. Top notch Wasm support, cross compiling is a breeze. That said, coming from a FP background (mostly Haskell/JS, now TS) Rust is... hard. I do understand the basic rules of the borrow checker, I do conceptually understand lifetimes, but actually using th…
It is definitely not easier compared to C++, contrasting with D, which is easier than C++.
However, the program worked correctly at the first try, which I guess it is also a consequence of the Rust model.
Re: Rust 1.46
#98So, I want to learn Rust. I am a C# / Python programmer, experienced. Are there any particular set of problems that I can solve systematically, so that I can learn all the features of Rust?
It also taught me about Boxes and Rc's, which are essential for certain kinds of things, and which I don't remember being covered in the main Rust Book at all
Re: Rust 1.46
#99These const fn’s are cool, but won’t this also lead to long compile times down the road?
Yes, any time you move computation to compile time, it makes the compile time take longer. As always it is a tradeoff. One thing that people may not realize, especially now that we have loop. You may expect this to hang the compiler: const fn forever() -> ! { loop { } } static FOO: u32 = forever(); But it won't: error[E0080]: could not evaluate static initializer --> src/lib.rs:2:5 | 2 | / loop { 3 | | 4 | | } | | ^…
Re: Rust 1.46
#100So, I want to learn Rust. I am a C# / Python programmer, experienced. Are there any particular set of problems that I can solve systematically, so that I can learn all the features of Rust?
Once you've learned the basics (plenty of links in the siblings, including the official Rust Book), this is a key (and entertaining!) unofficial resource that really hammered home for me the ways that Rust is different from the C family when it comes to working with references: https://rust-unofficial.github.io/too-many-lists/ It also taught me about Boxes and Rc's, which are essential for certain kinds of things, an…