drop_this 0.0.0

Convenience traits to drop values of "this" specific type.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 8.86 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 253.49 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 8s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • SichangHe/drop_this.rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • SichangHe

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();