chitoyuu / lifelink Goto Github PK
View Code? Open in Web Editor NEWErase covariant lifetime parameters from anything, with generic associated types.
License: Apache License 2.0
Erase covariant lifetime parameters from anything, with generic associated types.
License: Apache License 2.0
When Deathtouch
is forgotten (e.g. via mem::forget
), this ends the borrow of the original variable without running the drop implementation of Deathtouch
. Thus, the lifelink
remains usable and this can lead to UB such as aliasing with &mut
or use after free:
fn main() {
use lifelink::{Lifelink, RefCtor};
let mut value = Box::new(4u8);
let (mut lifelink, deathtouch) = Lifelink::<RefCtor<u8>>::new(&*value);
let guard = lifelink.get().unwrap();
core::mem::forget(deathtouch);
println!("{}", *guard);
*value = 8; // guard aliases with mutable access
println!("{}", *guard);
drop(value);
println!("{}", *guard); // use after free
}
Since forgetting is safe, the current API is unsound.
LifeLink::new
accept a closure that is provided the lifelink
. Then use the scopeguard
crate (or the same techniques as scopeguard
) to ensure that the code to reclaim the borrow from the lifelink
always runs when that closure completes or panics.LifeLink::new
, that macro will place the Deathtouch
in a local that is automatically dropped at the end of the current scope, with the local defined inside the macro, user code will not be able to forget it since it can't be named outside of the macro (e.g. similar to scopeguard::defer!
).A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.