File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use std::path::PathBuf;
77use std:: { fs, io} ;
88
99#[ derive( Clone ) ]
10+ /// Defines a data source, either a source `std::path::PathBuf`, or a vector of bytes.
1011pub enum FileDataSource {
1112 File ( PathBuf ) ,
1213 Data ( Vec < u8 > ) ,
@@ -26,6 +27,7 @@ impl Debug for FileDataSource {
2627}
2728
2829impl FileDataSource {
30+ /// Get the length of the inner data source
2931 pub fn len ( & self ) -> anyhow:: Result < u64 > {
3032 Ok ( match self {
3133 FileDataSource :: File ( path) => fs:: metadata ( path)
@@ -34,7 +36,18 @@ impl FileDataSource {
3436 FileDataSource :: Data ( v) => v. len ( ) as u64 ,
3537 } )
3638 }
37-
39+ /// Copy this data source to the specified target that implements io::Write
40+ /// Example:
41+ /// ```
42+ /// let mut new_file = std::io::fs::OpenOptions::new()
43+ /// .read(true)
44+ /// .write(true)
45+ /// .create(true)
46+ /// .truncate(true)
47+ /// .open(to)?;
48+ ///
49+ /// f.source.copy_to(&mut new_file)?;
50+ ///```
3851 pub fn copy_to ( & self , target : & mut dyn io:: Write ) -> anyhow:: Result < ( ) > {
3952 match self {
4053 FileDataSource :: File ( file_path) => {
You can’t perform that action at this time.
0 commit comments