#![macro_use]
use unknown::IUnknown;
use std::ops::Deref;
pub struct ComRef<T> where T: IUnknown {
_ref: *const T,
}
impl<T: IUnknown> ComRef<T> {
pub fn new(value: *const T) -> ComRef<T> {
ComRef { _ref: value }
}
}
impl<T: IUnknown> Deref for ComRef<T> {
type Target = T;
#[inline(always)]
fn deref(&self) -> &T {
unsafe { &(*self._ref) }
}
}
impl<T: IUnknown> Drop for ComRef<T> {
fn drop(&mut self) {
if self._ref.is_null() { return; }
self.release();
}
}
impl<T: IUnknown> Clone for ComRef<T> {
#[inline]
fn clone(&self) -> ComRef<T> {
self.add_ref();
ComRef::new(self._ref)
}
}
impl<T: IUnknown> ::std::borrow::Borrow<T> for ComRef<T> {
fn borrow(&self) -> &T {
&*self
}
}
unsafe impl<T: IUnknown> Send for ComRef<T> {}