owned-drop

Crates.ioowned-drop
lib.rsowned-drop
version0.1.1
sourcesrc
created_at2022-12-14 16:55:52.942486
updated_at2022-12-17 12:01:34.139388
descriptionA wrapper that enables ownership on drop
homepage
repositoryhttps://github.com/terrarier2111/owned-drop
max_upload_size
id736691
size13,526
(terrarier2111)

documentation

README

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>) {
    /*
    ...
     */
}

Commit count: 6

cargo fmt