All Rust features explained

preview_player
Показать описание
In today's video, we 're going over most important features of the Rust programming language. Whether you're a complete beginner or an experienced developer this video will give you valuable insights into how Rust integrated features from other languages into a single masterpiece.

Chapters:
0:00 Overview
1:02 Feature 1
3:09 Feature 2
7:16 Feature 3
9:25 Feature 4
11:52 Feature 5
15:45 Feature 6
18:49 Feature 7
20:38 Conclusion
Рекомендации по теме
Комментарии
Автор

technically, async/await came from C# not javascript. and even more, async keyword was introduced in F# in 2007.

sv
Автор

One design choice by Rust that I consider a feature is the fact that unlike C/C++, variables are const by default and your must explicitly make them mutable. This helps to both guarantee that certain values don't get changed where they shouldn't, and also makes code easier to read because in C many folks forget about const, but in Rust mutable tells the reader of code that the writer of the code specifically wanted this variable to be mutable. I guess you sort of cover it in talking about borrowing but calling out C specifically might catch more people's attention.

ntrgc
Автор

8:53 I may be wrong, but the Box<> in Vec<Box<Employee>> is unnecessary and will cause extra allocations. You can put the Employee directly into Vec, since Vec already allocates them on the heap, so you won't get a recursive enum.

vnldces
Автор

NPM: 2010... PyPi: 2003... PECL: 2003... PEAR: 1999... CPAN: 1995. Yeah, Node didn't come up with the idea of the library package manager, not even close.

KaitharVideo
Автор

I think the RAII with the sqlite example could be implemented as an std::unique_ptr with a custom deleter(lamda that calls sqlite3_close()). Using a unique_ptr would also prevent unintended copying of the connection and having multiple objects pointing to it.

sledgex
Автор

in your C++ example about zero cost abstraction, the std::max_element function return an iterator which is the first occurrence of the maximum value found between the two iterators you gave.
if you try to read the resulted iterator directly, yes, it will be an undefined behavior. what you have to do instead is to compare the resulted iterator with the end iterator you gave in max_element (which is not inclusive). if those two are equal, it is like a None optional in rust : no max value found because of empty vector for example.

iamgly
Автор

I have to say, cargo is also my favorite feature. Just seeing all this green like instead of the crappy mess of makefile is really satisfying. And I feel like is always succeed execpt when some crate relied on C lib

wiiznokes
Автор

6:00 Its not magic. Rust uses the Drop trait for an equivalent to C++ destructors. In your example, the Connection type simply implements this Drop trait to implement the logic to release the connection. It would be identical to having a C++ class called DatabaseConnection with no destructor that stored a Connection class that had a destructor to close the connection.

undersquire
Автор

At 6:24, the point you're making about the no-aliasing rule is correct of course, but the example you're giving of invalid code actually compiles without any errors. It would've been an error in an early version of Rust, but since "nonlexical lifetimes" were added, the compiler has been smart enough to see that references you never touch again can be short-lived. To get code that's actually invalid, you need to mention one of the shared references again after the mutable reference was created.

oconnor
Автор

i just want to say that async does not come from JS but from C#

stevefan
Автор

the only bad thing about rust is the foundation

ulrich-tonmoy
Автор

Nice drill-down of core features (and how they came to be)! Already "signed up" for the Bootcamp, hope for its release SOONER than later! :) good work @Bogdan!

criptouni
Автор

Thanks for a very informative video. I especially enjoyed how you explained where some of the language features originated and how they are implemented in rust. The originators and community really put a lot of thought into improving the great features of other languages and making a first-class language simple to use.

andyvarella
Автор

Hi great video! May I make one suggestion, which is to annotate the timestamps with actual descriptions instead of "Feature X".

henrywang
Автор

2:26 Calling max_element on an empty vector is not undefined behavior, it returns an iterator pointing at the past-the-end element. Dereferencing that past-the-end iterator is UB, so your point stands. You still need to rely on the programmer to account for both cases, meanwhile in Rust the compiler forces you to account for them.

ThreeCheersme
Автор

and npm is not the first packaging system in programming languages...

sv
Автор

Awesome coverage of really cool features. Looking forward to what's coming next. Keep up the great work!

nkodoko
Автор

5:20 It is utterly unclear how one can compare C++ to Rust without ensuring an apples-to-apples comparison. If you are employing a type in Rust that can automatically close connections upon destruction, why would you not utilize an analogous type in C++? Conversely, if you prefer using a low-level API in C++, which necessitates closing connections manually, why would you not employ the same low-level API in Rust?

videocruncher
Автор

2:29 - No, calling max_element on an empty collection is perfectly defined behavior, and is handled similar to your Rust example. The returned iterator will be numbers.end() and you need to check for that case, similar to how you check for None in your Rust code.

The undefined behavior comes in because you unconditionally dereferenced your result without checking. It's the same as if you unconditionally called unwrap() on the result in your Rust example.

I really wish Rust people would be more honest about how C++ works and not try to magnify what is and is not undefined behavior. I think Rust is good enough at what it does that you don't need to misrepresent C++ to show Rust's strengths.

oracleoftroy
Автор

There is a problem in your RAII examples too :
You are telling Rust is better than C++ because ownership is integrated in the language and you don't have to call for a close function to quit the database. But that the same in C++ : Connection may implement Drop to close the connection on its own, like C++ does when the scope goes down. You show a full raw implementation in C++ but not in Rust, that's unfair to compare those code.

iamgly