file_storage/op/file/write/write_str.rs
1use crate::Operation::Write;
2use crate::Reason::FileAlreadyExists;
3use crate::{Error, FilePath};
4
5impl FilePath {
6 //! Write String
7
8 /// Writes the `string` to the file.
9 ///
10 /// Returns `Ok(())`.
11 /// Returns `Err(FileAlreadyExists)` if the file already exists.
12 pub fn write_str<S>(&self, string: S) -> Result<(), Error>
13 where
14 S: AsRef<str>,
15 {
16 if self.write_str_if_not_exists(string.as_ref())? {
17 Ok(())
18 } else {
19 Err(Error::new(self.clone(), Write, FileAlreadyExists))
20 }
21 }
22}