consumable 0.1.0

Consume the value by replacing it with the default value and returning the previous value
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 2.86 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 242.44 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Thomas-Mewily/consumable
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Thomas-Mewily

Consume the value by replacing it with the default value and returning the previous value

use consumable::*;

let mut x : i32 = 42;
assert_eq!(x.consume(), 42);
assert_eq!(x, i32::default());
pub trait Consumable
{
    fn consume(&mut self) -> Self;
}

impl<T : Default> Consumable for T 
{
    fn consume(&mut self) -> Self { std::mem::take(self) }
}