-
Notifications
You must be signed in to change notification settings - Fork 238
Open
Description
This is an idea I'm thinking about these days, we should be able to not retain things when using the get rule, instead we should be able to rely on lifetimes.
use std::ops::{Deref, Drop};
pub trait Release {
unsafe fn release(&self);
}
pub struct Retained<T>(T) where T: Release;
impl<T: Release> Drop for Retained<T> {
fn drop(&mut self) {
unsafe {
self.0.release();
}
}
}
enum Opaque {}
pub struct CFURL(Opaque);
pub struct CFURLRef(*const CFURL);
impl Release for CFURLRef {
unsafe fn release(&self) {
...
}
}
impl Deref for CFURLRef {
type Target = CFURL;
fn deref(&self) -> &CFURL {
unsafe { &*self.0 }
}
}With additional traits for casting to supertype CFTypeRef, we should be able to provide functions going from &CFString to Retained<CFStringRef>.
Metadata
Metadata
Assignees
Labels
No labels