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