-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Inspired by #224
All methods that return auto-referenced objects have this common property: they assume ARP alive, and they could return a reference with a lifetime not greater than that ARP. This can be directly expressed with the type system instead of being implicit:
let bar = {
let arp = metal::AutoReleasePool::new();
let foo = device.create_foo(&arp);
foo.to_owned()
};
Notice how ARP becomes a regular object with RAII instead of being closure-based.
Why this is cool?
- ARP is explicitly used, therefore no need to fight Rust "unused variable" warnings that often occur with similar RAII APIs
- metal-rs clearly expresses the dependency on ARP, there is no assumption taking place
- everything is forcefully safe, since returned references live no longer than the ARP
- metal-rs is zero overhead, since it doesn't do "retain" just to be able to return an owned object
Metadata
Metadata
Assignees
Labels
No labels