Crates.io | drop_this |
lib.rs | drop_this |
version | 0.0.0 |
source | src |
created_at | 2024-06-24 03:02:55.565242 |
updated_at | 2024-06-24 03:02:55.565242 |
description | Convenience traits to drop values of "this" specific type. |
homepage | |
repository | https://github.com/SichangHe/drop_this.rs |
max_upload_size | |
id | 1281743 |
size | 8,868 |
At times, you may want to ignore the output of some function calls. However, there is the danger of ignoring the wrong values. For example, consider this code below sending a message through a channel:
_ = sender.send(msg);
Is this correct? Well, it depends on the channel.
Some channels' send
methods are asynchronous, in that case,
the code above creates a Future
and ignores it—clearly a mistake;
other channels have a synchronous send
method, so the code would be correct…
The core problem lies in the fact that drop
and _ = …
are type-agnostic,
while you want to be type-aware when ignoring your values.
Therefore, the pro move drop_this
proposes would be:
use drop_this::*;
sender.send(msg).drop_result();