file_storage/op/file/write/
write_data.rs

1use crate::Operation::Write;
2use crate::Reason::FileAlreadyExists;
3use crate::{Error, FilePath};
4
5impl FilePath {
6    //! Write Data
7
8    /// Writes the `data` to the file.
9    ///
10    /// Returns `Ok(())`.
11    /// Returns `Err(FileAlreadyExists)` if the file already exists.
12    pub fn write_data<D>(&self, data: D) -> Result<(), Error>
13    where
14        D: AsRef<[u8]>,
15    {
16        if self.write_data_if_not_exists(data)? {
17            Ok(())
18        } else {
19            Err(Error::new(self.clone(), Write, FileAlreadyExists))
20        }
21    }
22}