1- use crate :: app:: Result ;
1+ use crate :: app:: { Result , RuntimeError } ;
22#[ cfg( target_os = "windows" ) ]
33use std:: collections:: HashMap ;
44#[ cfg( target_os = "windows" ) ]
@@ -26,8 +26,9 @@ pub struct JobHandle {
2626impl JobHandle {
2727 pub fn create ( ) -> Result < Self > {
2828 unsafe {
29- let handle = CreateJobObjectW ( None , None )
30- . map_err ( |error| format ! ( "Failed to create job object: {}" , error) ) ?;
29+ let handle = CreateJobObjectW ( None , None ) . map_err ( |error| {
30+ RuntimeError :: Internal ( format ! ( "Failed to create job object: {}" , error) )
31+ } ) ?;
3132
3233 let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std:: mem:: zeroed ( ) ;
3334 info. BasicLimitInformation . LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE ;
@@ -38,7 +39,9 @@ impl JobHandle {
3839 & info as * const _ as * const _ ,
3940 std:: mem:: size_of :: < JOBOBJECT_EXTENDED_LIMIT_INFORMATION > ( ) as u32 ,
4041 )
41- . map_err ( |error| format ! ( "Failed to set job object information: {}" , error) ) ?;
42+ . map_err ( |error| {
43+ RuntimeError :: Internal ( format ! ( "Failed to set job object information: {}" , error) )
44+ } ) ?;
4245
4346 Ok ( Self { handle } )
4447 }
@@ -47,10 +50,13 @@ impl JobHandle {
4750 pub fn assign_process ( & self , pid : u32 ) -> Result < ( ) > {
4851 unsafe {
4952 let process_handle = OpenProcess ( PROCESS_SET_QUOTA | PROCESS_TERMINATE , false , pid)
50- . map_err ( |error| format ! ( "Failed to open process {}: {}" , pid, error) ) ?;
53+ . map_err ( |error| {
54+ RuntimeError :: Internal ( format ! ( "Failed to open process {}: {}" , pid, error) )
55+ } ) ?;
5156
52- AssignProcessToJobObject ( self . handle , process_handle)
53- . map_err ( |error| format ! ( "Failed to assign process to job: {}" , error) ) ?;
57+ AssignProcessToJobObject ( self . handle , process_handle) . map_err ( |error| {
58+ RuntimeError :: Internal ( format ! ( "Failed to assign process to job: {}" , error) )
59+ } ) ?;
5460
5561 let _ = CloseHandle ( process_handle) ;
5662 Ok ( ( ) )
0 commit comments