11use std:: ffi:: { OsStr , OsString } ;
2+ #[ cfg( feature = "unstable" ) ]
3+ use std:: pin:: Pin ;
24
35use crate :: path:: Path ;
6+ #[ cfg( feature = "unstable" ) ]
7+ use crate :: prelude:: * ;
8+ #[ cfg( feature = "unstable" ) ]
9+ use crate :: stream:: { Extend , FromStream , IntoStream } ;
410
511/// This struct is an async version of [`std::path::PathBuf`].
612///
@@ -206,7 +212,7 @@ impl From<std::path::PathBuf> for PathBuf {
206212
207213impl Into < std:: path:: PathBuf > for PathBuf {
208214 fn into ( self ) -> std:: path:: PathBuf {
209- self . inner . into ( )
215+ self . inner
210216 }
211217}
212218
@@ -233,3 +239,44 @@ impl AsRef<std::path::Path> for PathBuf {
233239 self . inner . as_ref ( )
234240 }
235241}
242+
243+ #[ cfg( feature = "unstable" ) ]
244+ impl < P : AsRef < Path > > Extend < P > for PathBuf {
245+ fn stream_extend < ' a , S : IntoStream < Item = P > > (
246+ & ' a mut self ,
247+ stream : S ,
248+ ) -> Pin < Box < dyn Future < Output = ( ) > + ' a > >
249+ where
250+ P : ' a ,
251+ <S as IntoStream >:: IntoStream : ' a ,
252+ {
253+ let stream = stream. into_stream ( ) ;
254+
255+ //TODO: This can be added back in once this issue is resolved:
256+ // https://github.com/rust-lang/rust/issues/58234
257+ //self.reserve(stream.size_hint().0);
258+
259+ Box :: pin ( stream. for_each ( move |item| self . push ( item. as_ref ( ) ) ) )
260+ }
261+ }
262+
263+ #[ cfg( feature = "unstable" ) ]
264+ impl < ' b , P : AsRef < Path > + ' b > FromStream < P > for PathBuf {
265+ #[ inline]
266+ fn from_stream < ' a , S : IntoStream < Item = P > > (
267+ stream : S ,
268+ ) -> Pin < Box < dyn core:: future:: Future < Output = Self > + ' a > >
269+ where
270+ <S as IntoStream >:: IntoStream : ' a ,
271+ {
272+ let stream = stream. into_stream ( ) ;
273+
274+ Box :: pin ( async move {
275+ pin_utils:: pin_mut!( stream) ;
276+
277+ let mut out = Self :: new ( ) ;
278+ out. stream_extend ( stream) . await ;
279+ out
280+ } )
281+ }
282+ }
0 commit comments