dxgi_win::interface! [] [src]

macro_rules! interface {
	(
		$interface:ident ($vtbl:ident) {$(
			fn $method:ident(&mut self $(,$arg:ident : $argty:ty)*) -> $retty:ty
		),*}
	) => {
		#[repr(C)]
		pub struct $vtbl {
			$(pub $method:
				Option<unsafe extern "system" fn(This: *mut $interface $(,$arg: $argty)*) -> $retty>
			),*
		}
		#[repr(C)]
		pub struct $interface {
			pub lpVtbl: *const $vtbl
		}
		impl $interface {
			$(pub unsafe fn $method(&mut self $(,$arg: $argty)*) -> $retty {
				((*self.lpVtbl).$method.unwrap())(self $(,$arg)*)
			})*
		}
	};

	(
		$interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident) {$(
			fn $method:ident(&mut self $(,$arg:ident : $argty:ty)*) -> $retty:ty
		),*}
	) => {
		#[repr(C)]
		pub struct $vtbl {
			pub parent: $pvtbl,
			$(pub $method:
				Option<unsafe extern "system" fn(This: *mut $interface $(,$arg: $argty)*) -> $retty>
			),*
		}
		#[repr(C)]
		pub struct $interface {
			pub lpVtbl: *const $vtbl
		}
		impl $interface {
			$(pub unsafe fn $method(&mut self $(,$arg: $argty)*) -> $retty {
				((*self.lpVtbl).$method.unwrap())(self $(,$arg)*)
			})*
		}
		impl ::std::ops::Deref for $interface {
			type Target = $pinterface;
			fn deref(&self) -> &$pinterface {
				unsafe { ::std::mem::transmute(self) }
			}
		}
		impl ::std::ops::DerefMut for $interface {
			fn deref_mut(&mut self) -> &mut $pinterface {
				unsafe { ::std::mem::transmute(self) }
			}
		}
	};
}