file_storage/path/mutate/
make_folder.rs1use crate::{FilePath, FolderPath, StoragePath};
2
3impl StoragePath {
4 pub fn clone_make_folder(&self) -> FolderPath {
10 let path: StoragePath = if self.is_folder() {
11 self.clone()
12 } else {
13 self.clone_with_extra_capacity(self.file_separator().len_utf8())
14 .with_appended_char(self.file_separator())
15 };
16 unsafe { FolderPath::new(path) }
18 }
19
20 pub fn make_folder(self) -> FolderPath {
24 let path: StoragePath = if self.is_folder() {
25 self
26 } else {
27 let fs: char = self.file_separator();
28 self.with_appended_char(fs)
29 };
30 unsafe { FolderPath::new(path) }
32 }
33}
34
35impl FilePath {
36 pub fn make_folder(self) -> FolderPath {
40 self.to_path().make_folder()
41 }
42}
43
44#[cfg(test)]
45mod tests {
46 use crate::StoragePath;
47
48 #[test]
49 fn make_folder() {
50 let path: StoragePath = StoragePath::unix_root();
51
52 let path: StoragePath = path.make_folder().to_path();
53 assert_eq!(path.as_str(), "/");
54
55 let path: StoragePath = path.with_appended("folder.txt").make_folder().to_path();
56 assert_eq!(path.as_str(), "/folder.txt/");
57 }
58}