file_storage/path/mutate/
append_char.rs1use crate::{FilePath, FolderPath, StoragePath};
2
3impl StoragePath {
4 pub fn append_char(&mut self, c: char) {
8 unsafe { self.path_mut() }.push(c);
9 }
10
11 pub fn with_appended_char(mut self, c: char) -> Self {
13 self.append_char(c);
14 self
15 }
16}
17
18impl FilePath {
19 pub fn with_appended_char(self, c: char) -> StoragePath {
23 self.to_path().with_appended_char(c)
24 }
25}
26
27impl FolderPath {
28 pub fn with_appended_char(self, c: char) -> StoragePath {
32 self.to_path().with_appended_char(c)
33 }
34}
35
36#[cfg(test)]
37mod tests {
38 use crate::{FilePath, FolderPath, StoragePath};
39 use std::error::Error;
40
41 #[test]
42 fn append() -> Result<(), Box<dyn Error>> {
43 let path: StoragePath = StoragePath::unix_root();
44 let result: StoragePath = path.with_appended_char('c');
45 assert_eq!(result.as_str(), "/c");
46
47 let file: FilePath = FolderPath::unix_root().make_file("file")?;
48 let result: StoragePath = file.with_appended_char('c');
49 assert_eq!(result.as_str(), "/filec");
50
51 let folder: FolderPath = FolderPath::unix_root();
52 let result: StoragePath = folder.with_appended_char('c');
53 assert_eq!(result.as_str(), "/c");
54
55 Ok(())
56 }
57}