Implement Rust Async Future Trait with Tokio Executor 🦀 Rust Programming Tutorial for Developers

preview_player
Показать описание
In this video, we'll be exploring how you can implement the Rust standard library's Future trait on your own, custom data structures! The Future's output type and the poll() function are the only two things that you need to implement, but generally your custom type will also have helper functions of their own as well.

We'll also be exploring the Tokio async executor crate, and how you can easily enable multi-threading for futures! Tokio is the most popular async runtime for Rust, and you'll find tons of code samples that utilize Tokio. The tokio crate is broken down into a bunch of optional features. We'll take a look at how to identify the specific features we need to enable.

Please follow me on these other social channels!

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names,trademarks and brands does not imply endorsement.

#rustlang #rust #rustdev #opensource #software #linux #devops #programming #rusty #dev #coding #codinglife #code #coder #ubuntu #ubuntulinux #appdev #developer
Рекомендации по теме
Комментарии
Автор

💻✅ Check out some of these links to upgrade your digital life! Thanks for helping support this channel! 🦀🦀🦀

TrevorSullivan
Автор

📝QUICK CORRECTION: In this video, I mentioned that each iteration of the poll() method would be scheduled on a separate thread. However, it seems that the spawn() function schedules the entire future's lifetime on a given thread.

TrevorSullivan
Автор

Very nice example! I feel it's only missing the use of join! macro at the end to show how we can idiomatically await the completion of the tasks.

havefuntrading
Автор

I found this video incredibly helpful! Thank you so much, Trevor. I love your teaching style and how you code from scratch. You do an awesome job explaining as you go, and this was the first Rust / Tokio video I've found that didn't confuse the heck out of me.

sammorgan
Автор

I have watched most of the videos in the Rust tutorial series and have much much appreciated them. The one minor thing I might suggest to Trevor is to maybe script the videos a little more. They all seem a bit more "seat of your pants" than most videos. That's potentially both good and bad. The bad is that sometimes dead ends are run into because not enough time was spent honing the procedures before coding them. That then leads to needing to backtrack or correct mistakes that happened. Potentially incorrect information is presented that then has to be fixed, hopefully later in the video. The good of this is that real programming tends to proceed just like that - lots of false starts, dead ends, and mistakes. By not covering up these slight errors and showing how he has to go back and fix things he is actually doing two very good things 1. showing that all programmers are human and mistakes happen 2. showing how to fix things when they go wrong. So, I'm a little on the fence as to whether the way the videos are constructed is genius or slightly sloppy. I'm leaning toward this format maybe being more good than bad because the process seems so genuine and relatable. Also, fixing mistakes may actually help to reinforce the correct way of doing things by showing how to fix slightly wrong ways of doing things. So, I hope this doesn't come off as negative. Actually, it's a kind of interesting way to present material that might even be better than honing the presentation to perfection like most people try to do.

CKidder
Автор

I've also watched most of your videos, Trevor. Since I'm relatively new to Rust, I really appreciate how you explain the concepts and give examples. I know it might extend the video length, but if you encounter an error, instead of pausing and fixing it off-camera, could you share how you found the problem? Because the process of identifying and resolving errors can also be helpful for viewers. I think this aligns with your approach of making videos realistically. Alternatively, you could be a bit more prepared with the examples to avoid running into major errors that require stopping to figure out, giving viewers a clearer roadmap rather than showing them broken code that you then need to correct, which might cause confusion. 🥰

mrtruongleo
Автор

Some of us are on windows servers, how do we check for these threads and adjust them as well?

Dhanhyyy
Автор

This is making so much click for me. Thank you! SUBSCRIBED.

Wodziwob
Автор

Thank you for this video it is very useful to see a real example!!

shailendrajadhav
Автор

You usually shouldn't use std threading stuff like sleep ( as you did in the first example) when working wih futures in tokio. Instead tokio provides its own utilities like tokio::time::sleep

ghostsssssss
Автор

Great video but have to be careful! If you where to have only one CPU by your computer then sleep function would block all your spawn threads! That is the reason why they say that high CPU intensive work is better for parallel programming instead of async. That is because if you do not await you will be blocking other async work. Remember to use the tokio sleep function that has an await. Then that sleep function will hand work. That is the reason why you finally saw other threads on your computer finally being used.

TonoNamnum
Автор

38:18 check if its some variante and then unwrap has a good idiomatic method "and_then" that you unintentionally mentioned :P

NotherPleb
Автор

completed_laps and self.laps are completely useless... you could just pop the Vec and match and decide whether to update the value then Poll::Pending, or just Ready. I'm a little puzzled why you did this...

lostphysicist
Автор

Just in time, I am writing an application using Tokio. I was looking over the docs today. And now this vid.

LibreGlider
Автор

Very good and instructive video!
Observation:
There is no need to use "return".

claudiofsr
Автор

Nice video Trevor. Have you considered adding a donate button to your channel?

sanjsahayam
Автор

Hi trevor. im trying to download some videos but i cant bc is encrypted can ou help me?

mafemayrink
Автор

Thank you Trevor! Is it code-server on lxd vm?

B-geqy
Автор

I feel like implementing my own futures is insanely not productive. I simply want to build some web APIs and be done with it. It breaks my heart to to let go of off rust but I just don’t see being productive with it

PaleyBlog
Автор

really great video but please dont use such complex example. Here to understand future not f1 racer cars.

Graveness
join shbcf.ru