File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ impl Pid {
4141 /// [pidfd]: https://man7.org/linux/man-pages/man2/pidfd_open.2.html
4242 #[ inline]
4343 pub const fn from_raw ( raw : RawPid ) -> Option < Self > {
44- debug_assert ! ( raw > 0 ) ;
44+ debug_assert ! ( raw >= 0 ) ;
4545 match NonZeroI32 :: new ( raw) {
4646 Some ( non_zero) => Some ( Self ( non_zero) ) ,
4747 None => None ,
@@ -79,6 +79,8 @@ impl Pid {
7979 }
8080
8181 /// Converts a `Pid` into a `RawPid`.
82+ ///
83+ /// This is the same as `self.as_raw_nonzero().get()`.
8284 #[ inline]
8385 pub const fn as_raw_pid ( self ) -> RawPid {
8486 self . 0 . get ( )
@@ -121,4 +123,18 @@ mod tests {
121123 transmute:: <Option <Pid >, RawPid >( Some ( Pid :: from_raw_unchecked( 4567 ) ) )
122124 } ) ;
123125 }
126+
127+ #[ test]
128+ fn test_ctors ( ) {
129+ use std:: num:: NonZero ;
130+ assert ! ( Pid :: from_raw( 0 ) . is_none( ) ) ;
131+ assert_eq ! ( Pid :: from_raw( 77 ) . unwrap( ) . as_raw_nonzero( ) , NonZero :: new( 77 ) . unwrap( ) ) ;
132+ assert_eq ! ( Pid :: from_raw( 77 ) . unwrap( ) . as_raw_pid( ) , 77 ) ;
133+ assert_eq ! ( Pid :: as_raw( Pid :: from_raw( 77 ) ) , 77 ) ;
134+ }
135+
136+ #[ test]
137+ fn test_specials ( ) {
138+ assert ! ( Pid :: from_raw( 1 ) . unwrap( ) . is_init( ) ) ;
139+ }
124140}
You can’t perform that action at this time.
0 commit comments