@@ -1676,6 +1676,20 @@ impl ExitCode {
16761676 pub const FAILURE : ExitCode = ExitCode ( imp:: ExitCode :: FAILURE ) ;
16771677}
16781678
1679+ impl ExitCode {
1680+ // This should not be stabilized when stabilizing ExitCode, we don't know that i32 will serve
1681+ // all usecases, for example windows seems to use u32, unix uses the 8-15th bits of an i32, we
1682+ // likely want to isolate users anything that could restrict the platform specific
1683+ // representation of an ExitCode
1684+ //
1685+ // More info: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
1686+ #[ unstable( feature = "process_exitcode_placeholder" , issue = "48711" ) ]
1687+ /// Convert an ExitCode into an i32
1688+ pub fn to_i32 ( self ) -> i32 {
1689+ self . 0 . as_i32 ( )
1690+ }
1691+ }
1692+
16791693impl Child {
16801694 /// Forces the child process to exit. If the child has already exited, an [`InvalidInput`]
16811695 /// error is returned.
@@ -2016,20 +2030,20 @@ pub fn id() -> u32 {
20162030pub trait Termination {
20172031 /// Is called to get the representation of the value as status code.
20182032 /// This status code is returned to the operating system.
2019- fn report ( self ) -> i32 ;
2033+ fn report ( self ) -> ExitCode ;
20202034}
20212035
20222036#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20232037impl Termination for ( ) {
20242038 #[ inline]
2025- fn report ( self ) -> i32 {
2039+ fn report ( self ) -> ExitCode {
20262040 ExitCode :: SUCCESS . report ( )
20272041 }
20282042}
20292043
20302044#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20312045impl < E : fmt:: Debug > Termination for Result < ( ) , E > {
2032- fn report ( self ) -> i32 {
2046+ fn report ( self ) -> ExitCode {
20332047 match self {
20342048 Ok ( ( ) ) => ( ) . report ( ) ,
20352049 Err ( err) => Err :: < !, _ > ( err) . report ( ) ,
@@ -2039,14 +2053,14 @@ impl<E: fmt::Debug> Termination for Result<(), E> {
20392053
20402054#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20412055impl Termination for ! {
2042- fn report ( self ) -> i32 {
2056+ fn report ( self ) -> ExitCode {
20432057 self
20442058 }
20452059}
20462060
20472061#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20482062impl < E : fmt:: Debug > Termination for Result < !, E > {
2049- fn report ( self ) -> i32 {
2063+ fn report ( self ) -> ExitCode {
20502064 let Err ( err) = self ;
20512065 eprintln ! ( "Error: {:?}" , err) ;
20522066 ExitCode :: FAILURE . report ( )
@@ -2055,7 +2069,7 @@ impl<E: fmt::Debug> Termination for Result<!, E> {
20552069
20562070#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20572071impl < E : fmt:: Debug > Termination for Result < Infallible , E > {
2058- fn report ( self ) -> i32 {
2072+ fn report ( self ) -> ExitCode {
20592073 let Err ( err) = self ;
20602074 Err :: < !, _ > ( err) . report ( )
20612075 }
@@ -2064,7 +2078,7 @@ impl<E: fmt::Debug> Termination for Result<Infallible, E> {
20642078#[ unstable( feature = "termination_trait_lib" , issue = "43301" ) ]
20652079impl Termination for ExitCode {
20662080 #[ inline]
2067- fn report ( self ) -> i32 {
2068- self . 0 . as_i32 ( )
2081+ fn report ( self ) -> ExitCode {
2082+ self
20692083 }
20702084}
0 commit comments