Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created April 15, 2015 20:49
Show Gist options
  • Save XMPPwocky/6a43d281a0bc4ca1c138 to your computer and use it in GitHub Desktop.
Save XMPPwocky/6a43d281a0bc4ca1c138 to your computer and use it in GitHub Desktop.
Destroy:
````rust
trait Destroy {
/// Called only when panicking
pub fn destroy(&mut self);
}
````
Drop:
````rust
trait Drop {
/// Called when going out of scope. May safely be left uncalled, although this can leak memory or resources so it's not recommended.
/// Never called when panicking. (Notably, this could it O.K. to panic in Drop, which is nice.)
/// (Should panicking in Drop call Destroy?)
pub fn drop(&mut self);
}
````
Destroy works sorta like Drop does today; if you don't implement it explicitly, nothing happens when you're panicking.
Not implementing Drop now makes your type linear.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment