From 8898de1f97aff9965e1518ca5abb554275183a14 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Mon, 10 Dec 2018 21:02:04 -0800 Subject: Update cc crate to 1.0.25 This change updates the cc crate to version 1.0.25. Import subrepo cc/:cc at fe0a7acb6d3e22e03bf83bcbf89367be888b5448 --- cc/src/com.rs | 56 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'cc/src/com.rs') diff --git a/cc/src/com.rs b/cc/src/com.rs index bd8cce7..2b16475 100644 --- a/cc/src/com.rs +++ b/cc/src/com.rs @@ -19,7 +19,7 @@ use winapi::CoInitializeEx; use winapi::COINIT_MULTITHREADED; use winapi::{SysFreeString, SysStringLen}; use winapi::IUnknown; -use winapi::{S_OK, S_FALSE, HRESULT}; +use winapi::{HRESULT, S_FALSE, S_OK}; pub fn initialize() -> Result<(), HRESULT> { let err = unsafe { CoInitializeEx(null_mut(), COINIT_MULTITHREADED) }; @@ -30,8 +30,13 @@ pub fn initialize() -> Result<(), HRESULT> { Ok(()) } -pub struct ComPtr(*mut T) where T: Interface; -impl ComPtr where T: Interface { +pub struct ComPtr(*mut T) +where + T: Interface; +impl ComPtr +where + T: Interface, +{ /// Creates a `ComPtr` to wrap a raw pointer. /// It takes ownership over the pointer which means it does __not__ call `AddRef`. /// `T` __must__ be a COM interface that inherits from `IUnknown`. @@ -40,7 +45,11 @@ impl ComPtr where T: Interface { ComPtr(ptr) } /// Casts up the inheritance chain - pub fn up(self) -> ComPtr where T: Deref, U: Interface { + pub fn up(self) -> ComPtr + where + T: Deref, + U: Interface, + { ComPtr(self.into_raw() as *mut U) } /// Extracts the raw pointer. @@ -55,20 +64,31 @@ impl ComPtr where T: Interface { unsafe { &*(self.0 as *mut IUnknown) } } /// Performs QueryInterface fun. - pub fn cast(&self) -> Result, i32> where U: Interface { + pub fn cast(&self) -> Result, i32> + where + U: Interface, + { let mut obj = null_mut(); let err = unsafe { self.as_unknown().QueryInterface(&U::uuidof(), &mut obj) }; - if err < 0 { return Err(err); } + if err < 0 { + return Err(err); + } Ok(unsafe { ComPtr::from_raw(obj as *mut U) }) } } -impl Deref for ComPtr where T: Interface { +impl Deref for ComPtr +where + T: Interface, +{ type Target = T; fn deref(&self) -> &T { unsafe { &*self.0 } } } -impl Clone for ComPtr where T: Interface { +impl Clone for ComPtr +where + T: Interface, +{ fn clone(&self) -> Self { unsafe { self.as_unknown().AddRef(); @@ -76,9 +96,14 @@ impl Clone for ComPtr where T: Interface { } } } -impl Drop for ComPtr where T: Interface { +impl Drop for ComPtr +where + T: Interface, +{ fn drop(&mut self) { - unsafe { self.as_unknown().Release(); } + unsafe { + self.as_unknown().Release(); + } } } pub struct BStr(BSTR); @@ -102,7 +127,10 @@ pub trait ToWide { fn to_wide(&self) -> Vec; fn to_wide_null(&self) -> Vec; } -impl ToWide for T where T: AsRef { +impl ToWide for T +where + T: AsRef, +{ fn to_wide(&self) -> Vec { self.as_ref().encode_wide().collect() } @@ -110,7 +138,10 @@ impl ToWide for T where T: AsRef { self.as_ref().encode_wide().chain(Some(0)).collect() } } -pub trait FromWide where Self: Sized { +pub trait FromWide +where + Self: Sized, +{ fn from_wide(wide: &[u16]) -> Self; fn from_wide_null(wide: &[u16]) -> Self { let len = wide.iter().take_while(|&&c| c != 0).count(); @@ -122,4 +153,3 @@ impl FromWide for OsString { OsStringExt::from_wide(wide) } } - -- cgit v1.2.1