file_storage/op/file/write/
write_str.rs

1use crate::{Error, FilePath};
2
3impl FilePath {
4    //! Write String
5
6    /// Writes the `string` to the file.
7    ///
8    /// Returns `Ok(())`.
9    /// Returns `Err(FileAlreadyExists)` if the file already exists.
10    pub fn write_str<S>(&self, string: S) -> Result<(), Error>
11    where
12        S: AsRef<str>,
13    {
14        self.write_slice(string.as_ref())
15    }
16
17    /// Writes the `string` to the file if the file does not exist.
18    ///
19    /// Returns `Ok(true)` if the file was written.
20    /// Returns `Ok(false)` if the file already exists.
21    pub fn write_str_if_not_exists<S>(&self, string: S) -> Result<bool, Error>
22    where
23        S: AsRef<str>,
24    {
25        self.write_slice_if_not_exists(string.as_ref().as_bytes())
26    }
27}