A half-hour to learn Rust
61–70 of 342 posts
Re: A half-hour to learn Rust
#62Just want to take a moment a appreciate your efforts for writing this amazing article. Honestly it made it so easier to understand Rust especially for a beginner like me
Re: A half-hour to learn Rust
#63Re: A half-hour to learn Rust
#64Earlier quoted context omitted.
The wording that "'static means different things" is a bit misleading. It means the same thing, but the meaning different because of the context: Lifetime: lifetime means that the first lifetime outlives (is as long or longer) the second Type: lifetime means that the type is constrained by the lifetime. Because 'static means "the lifetime of the whole process". That means that the type is not constrained.
I find it very confusing. T: ‘a is T outlives ‘a; but types are not generated at runtime. All types are static; which is to say they are created at compile time and exist for the lifetime of the program. Or does rust generate type variants on the fly at runtime? I didn’t think it did... It is a constraint applied to arguments at compile time ... but r, that’s what I thought anyway.
Yes, that’s true, but you can make it a bit more specific by saying “all the references in T outlive ‘a”. Then it should make more sense, as references are generated at runtime.
This gets to the heart of what makes Rust an interesting language, as references are generated at runtime, but how long those references are valid for is checked at compile time using lifetime bounds.
Re: A half-hour to learn Rust
#65Re: A half-hour to learn Rust
#66Earlier quoted context omitted.
The wording that "'static means different things" is a bit misleading. It means the same thing, but the meaning different because of the context: Lifetime: lifetime means that the first lifetime outlives (is as long or longer) the second Type: lifetime means that the type is constrained by the lifetime. Because 'static means "the lifetime of the whole process". That means that the type is not constrained.
I find it very confusing. T: ‘a is T outlives ‘a; but types are not generated at runtime. All types are static; which is to say they are created at compile time and exist for the lifetime of the program. Or does rust generate type variants on the fly at runtime? I didn’t think it did... It is a constraint applied to arguments at compile time ... but r, that’s what I thought anyway.
T and T are different types altogether (although, being generic, they can resolve to the same type if 'a == 'b, but it's not required). All this happens at compile time.
When you say T: 'a you say that T is a subtype of 'a hence it lives longer.
https://doc.rust-lang.org/nomicon/subtyping.html
Maybe you're being confused by misconception 1 here?
https://github.com/pretzelhammer/rust-blog/blob/master/posts...
Type T, being generic, can be an OwnedStruct, but also an &'a BorrowedStruct or a StructWithReferences. The owned one is a subtype of 'static since it's owned, but the ones with lifetimes are subtypes of 'a which itself (being a generic lifetime) can be a subtype of 'static or any other lifetime. Again, all this happens and is checked at compile time. This ensures that at runtime, the actual references are alive as per their lifetimes without explicitly checking them anymore.
Re: A half-hour to learn Rust
#67That is the best article on Rust I've ever seen. Better than the Rust book. I've been saying that Rust needed a book that wasn't written by the designers of the language, who are too close to it. Now we have one.
Did a free course in December with him, and I'm still watching the classes because it has so much great info there.
Also I do recommend the Rust Programming, it really teaches you "how/why" use Rust.
To conclude, rust-learning (at GitHub) have great links, amazing articles about parts of the language, there is so much knowledge there, just go collect it :P
Re: A half-hour to learn Rust
#68(Side note: dear Apple, please add syntax coloring and code formatting for Rust to Xcode. You have Fortran and C Shell in the list, but not Rust or Go, which are much more popular!)
Re: A half-hour to learn Rust
#69Re: A half-hour to learn Rust
#70Earlier quoted context omitted.
Why use a Result whose error type is empty?
I should have said :) I am writing backtracking algorithms (think something like a Sudoku solver where we fill in values by guessing), and an 'Error' is when we can deduce the Sudoku cannot be filled in, so we have to backtrack. I find Rust's ? notation gives a very natural way of writing such algorithms. I don't care "why" filling in the Sudoku failed, particularly because the solver will typically fail millions of…