Skip to content

This crate allows you to perform actions on the owned T even after it was dropped.

License

Notifications You must be signed in to change notification settings

terrarier2111/owned-drop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

This crate allows you to perform actions on the owned T even after it was dropped.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages