#drop #values #traits #channel

drop_this

Convenience traits to drop values of "this" specific type

1 unstable release

new 0.0.0 Jun 24, 2024

#85 in #drop

Download history 148/week @ 2024-06-21

148 downloads per month
Used in 2 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–1.1MB
~19K SLoC