@@ -68,10 +68,29 @@ impl Fd {
68
68
}
69
69
}
70
70
71
- fn new_owned < T : IntoRawFd > ( fd : T ) -> Self {
71
+ unsafe fn new_owned < T : IntoRawFd > ( fd : T ) -> Self {
72
72
let raw_fd = fd. into_raw_fd ( ) ;
73
- // Safety: IntoRawFd::into_raw_fd must return a valid raw fd.
74
- unsafe { Fd :: Owned ( OwnedFd :: from_raw_fd ( raw_fd) ) }
73
+ Fd :: Owned ( OwnedFd :: from_raw_fd ( raw_fd) )
74
+ }
75
+ }
76
+
77
+ impl From < PipeRead > for Fd {
78
+ fn from ( pipe_read : PipeRead ) -> Self {
79
+ // Safety:
80
+ //
81
+ // PipeRead::into_raw_fd returns a valid fd and transfers the
82
+ // ownership of it.
83
+ unsafe { Self :: new_owned ( pipe_read) }
84
+ }
85
+ }
86
+
87
+ impl From < PipeWrite > for Fd {
88
+ fn from ( pipe_write : PipeWrite ) -> Self {
89
+ // Safety:
90
+ //
91
+ // PipeWrite::into_raw_fd returns a valid fd and transfers the
92
+ // ownership of it.
93
+ unsafe { Self :: new_owned ( pipe_write) }
75
94
}
76
95
}
77
96
@@ -82,7 +101,7 @@ impl Stdio {
82
101
StdioImpl :: Null => Ok ( ( Fd :: Null , None ) ) ,
83
102
StdioImpl :: Pipe => {
84
103
let ( read, write) = create_pipe ( ) ?;
85
- Ok ( ( Fd :: new_owned ( read) , Some ( write) ) )
104
+ Ok ( ( read. into ( ) , Some ( write) ) )
86
105
}
87
106
StdioImpl :: Fd ( fd) => Ok ( ( Fd :: Borrowed ( fd. as_raw_fd ( ) ) , None ) ) ,
88
107
}
@@ -94,7 +113,7 @@ impl Stdio {
94
113
StdioImpl :: Null => Ok ( ( Fd :: Null , None ) ) ,
95
114
StdioImpl :: Pipe => {
96
115
let ( read, write) = create_pipe ( ) ?;
97
- Ok ( ( Fd :: new_owned ( write) , Some ( read) ) )
116
+ Ok ( ( write. into ( ) , Some ( read) ) )
98
117
}
99
118
StdioImpl :: Fd ( fd) => Ok ( ( Fd :: Borrowed ( fd. as_raw_fd ( ) ) , None ) ) ,
100
119
}
0 commit comments