#drop #values #traits #channel

drop_this

Convenience traits to drop values of "this" specific type

1 unstable release

0.0.0 Jun 24, 2024

#75 in #drop

Download history 138/week @ 2024-06-20 43/week @ 2024-06-27 39/week @ 2024-07-04 25/week @ 2024-07-11 16/week @ 2024-07-25 4/week @ 2024-08-01 10/week @ 2024-08-08 4/week @ 2024-08-15 3/week @ 2024-08-22 10/week @ 2024-08-29 2/week @ 2024-09-05 18/week @ 2024-09-12 17/week @ 2024-09-19 15/week @ 2024-09-26 2/week @ 2024-10-03

53 downloads per month
Used in 4 crates

MIT license

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