@@ -6,9 +6,10 @@ mod _winapi {
66 use crate :: {
77 builtins:: PyStrRef ,
88 common:: windows:: ToWideString ,
9- convert:: { ToPyException , ToPyObject , ToPyResult } ,
9+ convert:: { ToPyException , ToPyResult } ,
1010 function:: { ArgMapping , ArgSequence , OptionalArg } ,
1111 stdlib:: os:: errno_err,
12+ windows:: WindowsSysResult ,
1213 PyObjectRef , PyResult , TryFromObject , VirtualMachine ,
1314 } ;
1415 use std:: ptr:: { null, null_mut} ;
@@ -56,67 +57,6 @@ mod _winapi {
5657 UI :: WindowsAndMessaging :: SW_HIDE ,
5758 } ;
5859
59- trait WindowsSysResultValue {
60- type Ok : ToPyObject ;
61- fn is_err ( & self ) -> bool ;
62- fn into_ok ( self ) -> Self :: Ok ;
63- }
64-
65- impl WindowsSysResultValue for RAW_HANDLE {
66- type Ok = HANDLE ;
67- fn is_err ( & self ) -> bool {
68- * self == windows_sys:: Win32 :: Foundation :: INVALID_HANDLE_VALUE
69- }
70- fn into_ok ( self ) -> Self :: Ok {
71- HANDLE ( self )
72- }
73- }
74-
75- impl WindowsSysResultValue for BOOL {
76- type Ok = ( ) ;
77- fn is_err ( & self ) -> bool {
78- * self == 0
79- }
80- fn into_ok ( self ) -> Self :: Ok { }
81- }
82-
83- struct WindowsSysResult < T > ( T ) ;
84-
85- impl < T : WindowsSysResultValue > WindowsSysResult < T > {
86- fn is_err ( & self ) -> bool {
87- self . 0 . is_err ( )
88- }
89- fn into_pyresult ( self , vm : & VirtualMachine ) -> PyResult < T :: Ok > {
90- if self . is_err ( ) {
91- Err ( errno_err ( vm) )
92- } else {
93- Ok ( self . 0 . into_ok ( ) )
94- }
95- }
96- }
97-
98- impl < T : WindowsSysResultValue > ToPyResult for WindowsSysResult < T > {
99- fn to_pyresult ( self , vm : & VirtualMachine ) -> PyResult {
100- let ok = self . into_pyresult ( vm) ?;
101- Ok ( ok. to_pyobject ( vm) )
102- }
103- }
104-
105- type HandleInt = usize ; // TODO: change to isize when fully ported to windows-rs
106-
107- impl TryFromObject for HANDLE {
108- fn try_from_object ( vm : & VirtualMachine , obj : PyObjectRef ) -> PyResult < Self > {
109- let handle = HandleInt :: try_from_object ( vm, obj) ?;
110- Ok ( HANDLE ( handle as isize ) )
111- }
112- }
113-
114- impl ToPyObject for HANDLE {
115- fn to_pyobject ( self , vm : & VirtualMachine ) -> PyObjectRef {
116- ( self . 0 as HandleInt ) . to_pyobject ( vm)
117- }
118- }
119-
12060 #[ pyfunction]
12161 fn CloseHandle ( handle : HANDLE ) -> WindowsSysResult < BOOL > {
12262 WindowsSysResult ( unsafe { windows_sys:: Win32 :: Foundation :: CloseHandle ( handle. 0 ) } )
0 commit comments