Rust: Drop Trait

preview_player
Показать описание
Running some code on cleanup.

When your variable is removed from scope, then the drop function is called on it. This is inserted by Rust.

Implementing the drop method yourself allows you to customize the cleanup code that needs to run when this instance goes out of scope.

You can use this implementation to release resources like files or network connections.

#rust #drop #cleanup

0:00 intro
0:32 Running Code on Cleanup with the Drop Trait
4:06 Dropping a Value Early with std::mem::drop

Links

Chapter 15, section 3
Running Code on Cleanup with the Drop Trait
Рекомендации по теме
Комментарии
Автор

Should have shown how the drop function is implemented. Which is literally an empty block.

WofWca
Автор

Great content, but tbh your thumbnail was a lil scary 😅
You need a bit more sleep and a bit less screen time.
Respectfully,
A Fellow Sleep-Deprived SWE

jm-alan
Автор

I would love if the Rust compiler called drop after last use, instead of when it exits scope. That's how I personally usually do it in C and C++ (when I manage by hand)

BastianInukChristensen
welcome to shbcf.ru