consumable

Crates.ioconsumable
lib.rsconsumable
version0.1.0
sourcesrc
created_at2024-10-29 15:18:46.169723
updated_at2024-10-29 15:18:46.169723
descriptionConsume the value by replacing it with the default value and returning the previous value
homepage
repositoryhttps://github.com/Thomas-Mewily/consumable
max_upload_size
id1427123
size2,869
Thomas Mewily (Thomas-Mewily)

documentation

README

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) }
}
Commit count: 1

cargo fmt