Skip to content

Make auto-release pools visible #225

@kvark

Description

@kvark

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?

  1. ARP is explicitly used, therefore no need to fight Rust "unused variable" warnings that often occur with similar RAII APIs
  2. metal-rs clearly expresses the dependency on ARP, there is no assumption taking place
  3. everything is forcefully safe, since returned references live no longer than the ARP
  4. metal-rs is zero overhead, since it doesn't do "retain" just to be able to return an owned object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions