Crates.io | consumable |
lib.rs | consumable |
version | 0.1.0 |
source | src |
created_at | 2024-10-29 15:18:46.169723 |
updated_at | 2024-10-29 15:18:46.169723 |
description | Consume the value by replacing it with the default value and returning the previous value |
homepage | |
repository | https://github.com/Thomas-Mewily/consumable |
max_upload_size | |
id | 1427123 |
size | 2,869 |
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) }
}