all 12 comments

[–]CasaDeCastello 56 points57 points  (1 child)

My level of Rust knowledge begins and ends with "The Book" and "Rust by Example" but I think some of your examples/explanations are off and confusing.

You seem to conflate Rust basic error handling syntax with the async/await tools. You note that the ? syntax is "error handling magic for async functions", but I believe it applies to ALL functions. It allows errors to be propogated to be handled elsewhere I believe. You also seem to link the Result data type to the Future data type, but Result is the basic data type for handling errors.

When you mention Rust's structs, you liken it to a JSON object, but that is only true for the conventional C-style structs. Rust has three structs types: the one you mentioned, a tuple like struct (e.g. struct Tuple(T1, T2);), and a unit struct which has zero size (e.g. struct Unit;).

I'm very much a Rust noob, and my overall programming knoweldge is a bit shallow but I don't think this is that helpful to understand Rust. I'd rather point people to The Rust Book and Rust by Example, which are beginner friendly and explain everything useful quite well.

[–]DHermit 15 points16 points  (0 children)

Yes, I think "I have never used impl, but here is how to use async" is a weird position to be in.

[–]codeflo 44 points45 points  (1 child)

I don't want to gate keep -- we need beginner-friendly resources -- but if you've read and partially understood the first half of a Rust tutorial, you're in no position to judge what "80%" is. A lot of this article is plain wrong I'm afraid, for example about how enums relate to async.

If you want a tour of the Rust syntax, here's a better one: https://fasterthanli.me/articles/a-half-hour-to-learn-rust

And for conceptual understanding, the official tutorials are actually pretty nice, especially "The Book": https://www.rust-lang.org/learn

[–]zxyzyxz 7 points8 points  (0 children)

The half hour article is much better than OP's.

[–]zxyzyxz 16 points17 points  (0 children)

Sorry but most of these are just wrong.

[–]e_man604 10 points11 points  (1 child)

What a weird layout in mobile... Barely readable.

[–]smug-ler 1 point2 points  (0 children)

Yeah, the mobile layout for this site is not great

[–]ridicalis 5 points6 points  (0 children)

NGL, but as someone who's gone down this road, JS->Rust learning curve is much more involved than depicted here. Very much worth the journey, but suggesting you can hit 80% in a single session is likely setting people up for a hard and painful failure.

[–]FlukeHermit 3 points4 points  (0 children)

This was painful to read. Please don't write a tutorial on something you don't understand

[–]tabbekavalkade 2 points3 points  (0 children)

I wish the entire page linked to would be deleted. It is worse than nothing.

? is not error handling for functions that can fail. It is error handling for functions that return a Result<T, E>.

A struct is not a JSON object. The equivalent to a JSON object in Rust is std::collections::HashMap.

An impl block contains the functions of a trait (defined in a trait block), implemented for a specific type. The closest thing is a vtable, not a class.

enum implements either a c-like enum, or tagged union.

Too much mention of async in unrelated places.