1 unstable release
0.0.0 | Jun 24, 2024 |
---|
#89 in #drop
41 downloads per month
Used in 4 crates
6KB
55 lines
Drop This
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();
lib.rs
:
Traits to provide a method for dropping values of specific types,
as an alternative to a type-agnostic drop
or _ =
assignment.
This is useful to avoid dropping the wrong type, e.g.,
when sending a message through a channel.
Dependencies
~0–5.5MB
~19K SLoC