File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,36 @@ impl FileWriteStr for ChildPath {
206
206
}
207
207
}
208
208
209
+ /// Write (copy) a file to [`ChildPath`].
210
+ ///
211
+ /// [`ChildPath`]: struct.ChildPath.html
212
+ pub trait FileWriteFile {
213
+ /// Write (copy) a file to [`ChildPath`].
214
+ ///
215
+ /// # Examples
216
+ ///
217
+ /// ```rust
218
+ /// use std::path::Path;
219
+ /// use assert_fs::prelude::*;
220
+ ///
221
+ /// let temp = assert_fs::TempDir::new().unwrap();
222
+ /// temp
223
+ /// .child("foo.txt")
224
+ /// .write_file(Path::new("Cargo.toml"))
225
+ /// .unwrap();
226
+ /// temp.close().unwrap();
227
+ /// ```
228
+ ///
229
+ /// [`ChildPath`]: struct.ChildPath.html
230
+ fn write_file ( & self , data : & path:: Path ) -> io:: Result < ( ) > ;
231
+ }
232
+
233
+ impl FileWriteFile for ChildPath {
234
+ fn write_file ( & self , data : & path:: Path ) -> io:: Result < ( ) > {
235
+ write_file ( self . path ( ) , data)
236
+ }
237
+ }
238
+
209
239
/// Copy files into [`TempDir`].
210
240
///
211
241
/// [`TempDir`]: struct.TempDir.html
@@ -268,6 +298,11 @@ fn write_str(path: &path::Path, data: &str) -> io::Result<()> {
268
298
write_binary ( path, data. as_bytes ( ) )
269
299
}
270
300
301
+ fn write_file ( path : & path:: Path , data : & path:: Path ) -> io:: Result < ( ) > {
302
+ fs:: copy ( data, path) ?;
303
+ Ok ( ( ) )
304
+ }
305
+
271
306
fn copy_files < S > (
272
307
target : & path:: Path ,
273
308
source : & path:: Path ,
Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ pub mod prelude {
81
81
pub use fixture:: PathCreateDir ;
82
82
pub use fixture:: FileTouch ;
83
83
pub use fixture:: FileWriteBin ;
84
+ pub use fixture:: FileWriteFile ;
84
85
pub use fixture:: FileWriteStr ;
85
86
pub use fixture:: PathChild ;
86
87
pub use fixture:: PathCopy ;
You can’t perform that action at this time.
0 commit comments