Crates.io | owned-drop |
lib.rs | owned-drop |
version | 0.1.1 |
source | src |
created_at | 2022-12-14 16:55:52.942486 |
updated_at | 2022-12-17 12:01:34.139388 |
description | A wrapper that enables ownership on drop |
homepage | |
repository | https://github.com/terrarier2111/owned-drop |
max_upload_size | |
id | 736691 |
size | 13,526 |
This crate allows one to get ownership of dropped data
Note: this crate supports no_std
Example
use owned_drop::OwnedDroppable;
use owned_drop::DropOwned;
fn do_stuff(owner: OwnerOfVec) {
let mut drop = DropOwned::new(owner);
// ...
// `drop` gets dropped here and `drop_owned` gets called.
}
struct OwnerOfVec {
data: Vec<String>,
}
impl OwnedDroppable for OwnerOfVec {
fn drop_owned(self) {
// This avoids a clone call one would normally have to do
// if one only had `&mut self` instead if `self`
function_requiring_ownership(self.data);
}
}
fn function_requiring_ownership(data: Vec<String>) {
/*
...
*/
}