Skip to content

Commit 502967b

Browse files
committed
Add documentation comments to FileDataSource and it's public methods.
1 parent 3a7fcf7 commit 502967b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/file_data_source.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::path::PathBuf;
77
use std::{fs, io};
88

99
#[derive(Clone)]
10+
/// Defines a data source, either a source `std::path::PathBuf`, or a vector of bytes.
1011
pub enum FileDataSource {
1112
File(PathBuf),
1213
Data(Vec<u8>),
@@ -26,6 +27,7 @@ impl Debug for FileDataSource {
2627
}
2728

2829
impl 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) => {

0 commit comments

Comments
 (0)