Skip to content

Commit

Permalink
Upgrade to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Boddlnagg committed May 18, 2019
1 parent ad20074 commit ac90ba5
Show file tree
Hide file tree
Showing 34 changed files with 1,660 additions and 1,659 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords = ["winrt", "uwp", "windows", "runtime", "com"]
categories = ["os::windows-apis", "api-bindings", "external-ffi-bindings"]
license = "MIT OR Apache-2.0"
exclude = ["Generator/**"]
edition = "2018"

[dependencies]
winapi = { version = "0.3", features = ["winnt", "combaseapi", "oleauto", "roapi", "roerrorapi", "hstring", "winstring", "winerror", "restrictederrorinfo"] }
Expand Down
2 changes: 1 addition & 1 deletion Generator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void WriteModuleTreeMultiFile(Module mod, DirectoryInfo directory, Strea
{
if (mod.IsEmpty) return;

const string IMPORTS = "use ::prelude::*;";
const string IMPORTS = "use crate::prelude::*;";

string name = mod.Name.ToLower();
string newPath = path == null ? mod.Name : (path + "." + mod.Name);
Expand Down
2 changes: 1 addition & 1 deletion Generator/Types/TypeDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public string GetPath(Module requestingModule)
}
else
{
name = $"::rt::gen::{ Module.Path }::{ Name }";
name = $"crate::{ Module.Path }::{ Name }";
}
var relative = $"{ Module.GetRelativePath(requestingModule) }::{ Name }";
if (relative.Length < name.Length)
Expand Down
2 changes: 1 addition & 1 deletion examples/hexdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CHUNK_SIZE: usize = 4096;

fn run() {
// Use the current executable as source file (because we know that will exist).
let exe_path = ::std::env::current_exe().expect("current_exe failed");
let exe_path = std::env::current_exe().expect("current_exe failed");
let exe_path_str = exe_path.to_str().expect("invalid unicode path");

let file = StorageFile::get_file_from_path_async(&*FastHString::new(&exe_path_str)).unwrap().blocking_get().expect("get_file_from_path_async failed").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn run() {
assert!(asi.close().is_ok());

// Walk directories up to root
let exe_path = ::std::env::current_exe().expect("current_exe failed");
let exe_path = std::env::current_exe().expect("current_exe failed");
let exe_path_str = exe_path.to_str().expect("invalid unicode path");
let file = StorageFile::get_file_from_path_async(&*FastHString::new(&exe_path_str)).unwrap().blocking_get().expect("get_file_from_path_async failed").unwrap();
println!("Executable file: {}", file.query_interface::<IStorageItem>().unwrap().get_path().unwrap());
Expand Down
6 changes: 3 additions & 3 deletions src/bstr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ::std::ptr;
use ::std::fmt;
use std::ptr;
use std::fmt;

use w::shared::wtypes::BSTR;
use w::shared::basetsd::UINT32;
Expand Down Expand Up @@ -63,7 +63,7 @@ impl BStr {
} else {
unsafe {
let len = self.len();
let slice: &[u16] = ::std::slice::from_raw_parts(self.0, len as usize);
let slice: &[u16] = std::slice::from_raw_parts(self.0, len as usize);
String::from_utf16_lossy(slice)
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/cominterfaces.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Guid;
use crate::Guid;
use w::um::unknwnbase::IUnknownVtbl;

/// Marker trait for all COM-compatible interfaces.
Expand All @@ -21,15 +21,15 @@ pub trait ComIid {
DEFINE_IID!(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);

/// Re-export from WinAPI crate
pub type IUnknown = ::w::um::unknwnbase::IUnknown;
pub type IUnknown = w::um::unknwnbase::IUnknown;
impl ComIid for IUnknown { #[inline] fn iid() -> &'static Guid { &IID_IUnknown } }
impl ComInterface for IUnknown { type Vtbl = IUnknownVtbl; }

DEFINE_IID!(IID_IRestrictedErrorInfo, 0x82BA7092, 0x4C88, 0x427D, 0xA7, 0xBC, 0x16, 0xDD, 0x93, 0xFE, 0xB6, 0x7E);

/// Re-export from WinAPI crate
pub type IRestrictedErrorInfo = ::w::um::restrictederrorinfo::IRestrictedErrorInfo;
pub type IRestrictedErrorInfoVtbl = ::w::um::restrictederrorinfo::IRestrictedErrorInfoVtbl;
pub type IRestrictedErrorInfo = w::um::restrictederrorinfo::IRestrictedErrorInfo;
pub type IRestrictedErrorInfoVtbl = w::um::restrictederrorinfo::IRestrictedErrorInfoVtbl;
impl ComIid for IRestrictedErrorInfo { #[inline] fn iid() -> &'static Guid { &IID_IRestrictedErrorInfo } }
impl ComInterface for IRestrictedErrorInfo { type Vtbl = IRestrictedErrorInfoVtbl; }

Expand All @@ -42,17 +42,17 @@ DEFINE_IID!(IID_IAgileObject, 0x94EA2B94, 0xE9CC, 0x49E0, 0xC0, 0xFF, 0xEE, 0x64
pub struct IAgileObject {
lpVtbl: *const IUnknownVtbl // IAgileObject has no methods besides what IUnknown has
}
impl ::std::ops::Deref for IAgileObject {
impl std::ops::Deref for IAgileObject {
type Target = IUnknown;
#[inline]
fn deref(&self) -> &IUnknown {
unsafe { ::std::mem::transmute(self) }
unsafe { std::mem::transmute(self) }
}
}
impl ::std::ops::DerefMut for IAgileObject {
impl std::ops::DerefMut for IAgileObject {
#[inline]
fn deref_mut(&mut self) -> &mut IUnknown {
unsafe { ::std::mem::transmute(self) }
unsafe { std::mem::transmute(self) }
}
}
impl ComIid for IAgileObject { #[inline] fn iid() -> &'static Guid { &IID_IAgileObject } }
Expand Down
34 changes: 17 additions & 17 deletions src/comptr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::{Deref, DerefMut};
use std::fmt;
use std::ptr;
use ::{ComIid, ComInterface, RtInterface, RtClassInterface, IInspectable, Guid};
use crate::{ComIid, ComInterface, RtInterface, RtClassInterface, IInspectable, Guid};

use w::shared::ntdef::VOID;
use w::shared::minwindef::LPVOID;
Expand Down Expand Up @@ -38,7 +38,7 @@ pub fn query_interface<T, Target>(interface: &T) -> Option<ComPtr<Target>> where

// This trait is not exported in the library interface
pub trait HiddenGetRuntimeClassName {
fn get_runtime_class_name(&self) -> ::HString;
fn get_runtime_class_name(&self) -> crate::HString;
}

impl<T> ComPtr<T> {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl<T> ComPtr<T> {
/// This is a runtime no-op, but you need to be sure that the interface is compatible.
#[inline]
pub unsafe fn into_unchecked<Interface>(self) -> ComPtr<Interface> where Interface: ComInterface {
::std::mem::transmute(self)
std::mem::transmute(self)
}

/// Gets the fully qualified name of the current Windows Runtime object.
Expand All @@ -101,7 +101,7 @@ impl<T> ComPtr<T> {
/// assert_eq!("Windows.Foundation.Uri", uri.get_runtime_class_name().to_string());
/// ```
#[inline]
pub fn get_runtime_class_name(&self) -> ::HString where T: RtClassInterface {
pub fn get_runtime_class_name(&self) -> crate::HString where T: RtClassInterface {
HiddenGetRuntimeClassName::get_runtime_class_name(self.as_inspectable())
}

Expand Down Expand Up @@ -151,12 +151,12 @@ impl<T> PartialEq<ComPtr<T>> for ComPtr<T> {
/// Owned array type that is used as return type when WinRT methods return arrays.
/// It wraps a block of memory that has been allocated by WinRT and will be deallocated
/// using `CoTaskMemFree` on drop.
pub struct ComArray<T> where T: ::RtType {
pub struct ComArray<T> where T: crate::RtType {
size: u32,
first: ptr::NonNull<T::Abi>
}

impl<T> ComArray<T> where T: ::RtType {
impl<T> ComArray<T> where T: crate::RtType {
#[inline]
pub unsafe fn from_raw(size: u32, first: *mut T::Abi) -> ComArray<T> {
assert!(!first.is_null());
Expand All @@ -173,25 +173,25 @@ impl<T> ComArray<T> where T: ::RtType {
}
}

impl<T> Deref for ComArray<T> where T: ::RtType {
impl<T> Deref for ComArray<T> where T: crate::RtType {
type Target = [T::OutNonNull];
#[inline]
fn deref(&self) -> &[T::OutNonNull] {
unsafe { ::std::slice::from_raw_parts(self.first.as_ptr() as *mut T::OutNonNull, self.size as usize) }
unsafe { std::slice::from_raw_parts(self.first.as_ptr() as *mut T::OutNonNull, self.size as usize) }
}
}
impl<T> DerefMut for ComArray<T> where T: ::RtType {
impl<T> DerefMut for ComArray<T> where T: crate::RtType {
#[inline]
fn deref_mut(&mut self) -> &mut [T::OutNonNull] {
unsafe { ::std::slice::from_raw_parts_mut(self.first.as_ptr() as *mut T::OutNonNull, self.size as usize) }
unsafe { std::slice::from_raw_parts_mut(self.first.as_ptr() as *mut T::OutNonNull, self.size as usize) }
}
}

impl<T> Drop for ComArray<T> where T: ::RtType {
impl<T> Drop for ComArray<T> where T: crate::RtType {
#[inline]
fn drop(&mut self) {
unsafe {
::std::ptr::drop_in_place(&mut self[..]);
std::ptr::drop_in_place(&mut self[..]);
CoTaskMemFree(self.first.as_ptr() as LPVOID)
};
}
Expand All @@ -202,8 +202,8 @@ mod extra {
// i.e. when a compiler version is used that still has dropflags
#[inline]
fn assert_no_dropflags() {
let p: *mut ::IInspectable = ::std::ptr::null_mut();
let _: ::ComPtr<::IInspectable> = unsafe { ::std::mem::transmute(p) };
let p: *mut crate::IInspectable = std::ptr::null_mut();
let _: crate::ComPtr<crate::IInspectable> = unsafe { std::mem::transmute(p) };
}
}

Expand All @@ -213,10 +213,10 @@ mod tests {

#[test]
fn check_sizes() {
use ::std::mem::size_of;
use std::mem::size_of;

// make sure that ComPtr is pointer-sized
assert_eq!(size_of::<::ComPtr<::IInspectable>>(), size_of::<*mut ::IInspectable>());
assert_eq!(size_of::<Option<::ComPtr<::IInspectable>>>(), size_of::<*mut ::IInspectable>());
assert_eq!(size_of::<crate::ComPtr<crate::IInspectable>>(), size_of::<*mut crate::IInspectable>());
assert_eq!(size_of::<Option<crate::ComPtr<crate::IInspectable>>>(), size_of::<*mut crate::IInspectable>());
}
}
4 changes: 2 additions & 2 deletions src/guid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ mod tests {

#[test]
fn check_size() {
use ::std::mem::size_of;
use std::mem::size_of;

assert_eq!(size_of::<::Guid>(), size_of::<::w::shared::guiddef::GUID>());
assert_eq!(size_of::<crate::Guid>(), size_of::<w::shared::guiddef::GUID>());
}
}
12 changes: 6 additions & 6 deletions src/hstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn internal_to_string(hstr: HSTRING) -> String {
unsafe {
let mut len = 0;
let buf = WindowsGetStringRawBuffer(hstr, &mut len);
let slice: &[u16] = ::std::slice::from_raw_parts(buf, len as usize);
let slice: &[u16] = std::slice::from_raw_parts(buf, len as usize);
String::from_utf16_lossy(slice)
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ impl HString {
pub fn make_reference<'a>(&'a self) -> HStringReference<'a> {
let mut len = 0;
let buf = unsafe { WindowsGetStringRawBuffer(self.0, &mut len) };
unsafe { HStringReference::from_utf16_unchecked(::std::slice::from_raw_parts(buf, len as usize + 1)) }
unsafe { HStringReference::from_utf16_unchecked(std::slice::from_raw_parts(buf, len as usize + 1)) }
}
}

Expand All @@ -467,7 +467,7 @@ impl Drop for HString {

unsafe impl Send for HString {}

impl ::std::clone::Clone for HString {
impl std::clone::Clone for HString {
#[inline]
fn clone(&self) -> Self {
let mut clone = HString::empty();
Expand Down Expand Up @@ -577,9 +577,9 @@ mod tests {

#[test]
fn check_sizes() {
use ::std::mem::size_of;
assert_eq!(size_of::<::HString>(), size_of::<::w::winrt::hstring::HSTRING>());
assert_eq!(size_of::<&::HStringArg>(), size_of::<::w::winrt::hstring::HSTRING>());
use std::mem::size_of;
assert_eq!(size_of::<crate::HString>(), size_of::<w::winrt::hstring::HSTRING>());
assert_eq!(size_of::<&crate::HStringArg>(), size_of::<w::winrt::hstring::HSTRING>());
}

#[test]
Expand Down
38 changes: 19 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ mod guid;
pub use guid::Guid;

///Represents the trust level of an activatable class (re-export from WinAPI crate)
pub type TrustLevel = ::w::winrt::inspectable::TrustLevel;
pub type TrustLevel = w::winrt::inspectable::TrustLevel;

// Compared to the DEFINE_GUID macro from winapi, this one creates a private const
macro_rules! DEFINE_IID {
(
$name:ident, $l:expr, $w1:expr, $w2:expr, $b1:expr, $b2:expr, $b3:expr, $b4:expr, $b5:expr,
$b6:expr, $b7:expr, $b8:expr
) => {
const $name: &'static ::Guid = &::Guid {
const $name: &'static crate::Guid = &crate::Guid {
Data1: $l,
Data2: $w1,
Data3: $w2,
Expand All @@ -67,33 +67,33 @@ mod rt;
pub use rt::{RtInterface, RtClassInterface, RtNamedClass, RtValueType, RtType, RtActivatable,
RtDefaultConstructible, IInspectable, IInspectableVtbl, IActivationFactory,
IMemoryBufferByteAccess, Char, RuntimeContext, IteratorAdaptor};
pub use rt::async::{RtAsyncAction, RtAsyncOperation};
pub use rt::async_util::{RtAsyncAction, RtAsyncOperation};

mod result;
pub use result::{Result, Error, HRESULT};

pub mod windows {
pub use rt::gen::windows::*;
pub use crate::rt::gen::windows::*;
}

/// This is only for internal use within the generated code
mod prelude {
pub use ::rt::{RtType, RtActivatable, IInspectable, IInspectableVtbl, IActivationFactory, Char};
pub use ::rt::handler::IntoInterface;
pub use ::cominterfaces::{ComInterface, ComIid, IUnknown};
pub use ::comptr::{ComPtr, ComArray};
pub use ::hstring::{HString, HStringArg};
pub use ::result::{Result, HRESULT};
pub use ::w::winrt::hstring::HSTRING;
pub use ::w::shared::winerror::S_OK;
pub use ::w::um::unknwnbase::IUnknownVtbl;
pub use ::std::ptr::null_mut;
pub use ::std::mem::zeroed;
pub use ::guid::Guid;
pub use ::rt::gen::windows::foundation;
pub use crate::rt::{RtType, RtActivatable, IInspectable, IInspectableVtbl, IActivationFactory, Char};
pub use crate::rt::handler::IntoInterface;
pub use crate::cominterfaces::{ComInterface, ComIid, IUnknown};
pub use crate::comptr::{ComPtr, ComArray};
pub use crate::hstring::{HString, HStringArg};
pub use crate::result::{Result, HRESULT};
pub use w::winrt::hstring::HSTRING;
pub use w::shared::winerror::S_OK;
pub use w::um::unknwnbase::IUnknownVtbl;
pub use std::ptr::null_mut;
pub use std::mem::zeroed;
pub use crate::guid::Guid;
pub use crate::rt::gen::windows::foundation;

#[inline]
pub fn err<T>(hr: ::result::HRESULT) -> ::result::Result<T> {
Err(::result::Error::from_hresult(hr))
pub fn err<T>(hr: crate::result::HRESULT) -> crate::result::Result<T> {
Err(crate::result::Error::from_hresult(hr))
}
}
8 changes: 4 additions & 4 deletions src/result.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt;

/// Re-export from WinAPI crate
pub type HRESULT = ::w::um::winnt::HRESULT;
pub type HRESULT = w::um::winnt::HRESULT;

// TODO: add more codes from https://msdn.microsoft.com/en-us/library/windows/desktop/dd542643(v=vs.85).aspx, especially the `RO_`-prefixed

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Error {
#[inline]
pub fn from_hresult(hr: HRESULT) -> Error {
use Error::*;
use ::w::shared::winerror::*;
use w::shared::winerror::*;

match hr {
E_ABORT => OperationAborted,
Expand All @@ -77,7 +77,7 @@ impl Error {
#[inline]
pub fn as_hresult(&self) -> HRESULT {
use Error::*;
use ::w::shared::winerror::*;
use w::shared::winerror::*;

match *self {
OperationAborted => E_ABORT,
Expand All @@ -100,4 +100,4 @@ impl Error {
}

/// A specialized `Result` type for Windows Runtime method calls.
pub type Result<T> = ::std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;
8 changes: 4 additions & 4 deletions src/rt/async.rs → src/rt/async_util.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::sync::{Arc, Mutex, Condvar};

use ::{
use crate::{
RtType,
ComIid,
Result
};

use ::windows::foundation::{
use crate::windows::foundation::{
IAsyncInfo,
IAsyncAction,
AsyncActionCompletedHandler,
Expand Down Expand Up @@ -44,10 +44,10 @@ macro_rules! impl_blocking_wait {
($handler:ident) => {
#[inline]
fn blocking_wait(&self) {
let info = ::comptr::query_interface::<_, IAsyncInfo>(self).expect("query_interface failed");
let info = crate::comptr::query_interface::<_, IAsyncInfo>(self).expect("query_interface failed");
let status = info.get_status().expect("get_status failed");

if status == ::windows::foundation::AsyncStatus::Completed {
if status == crate::windows::foundation::AsyncStatus::Completed {
return;
}

Expand Down
Loading

0 comments on commit ac90ba5

Please sign in to comment.