use crate::{FilePath, FolderPath, StoragePath};
impl StoragePath {
pub fn clone_make_folder(&self) -> FolderPath {
let path: StoragePath = if self.is_folder() {
self.clone()
} else {
self.clone_with_extra_capacity(self.file_separator().len_utf8())
.with_appended_char(self.file_separator())
};
unsafe { FolderPath::new(path) }
}
pub fn make_folder(self) -> FolderPath {
let path: StoragePath = if self.is_folder() {
self
} else {
let fs: char = self.file_separator();
self.with_appended_char(fs)
};
unsafe { FolderPath::new(path) }
}
}
impl FilePath {
pub fn make_folder(self) -> FolderPath {
self.to_path().make_folder()
}
}
#[cfg(test)]
mod tests {
use crate::StoragePath;
#[test]
fn make_folder() {
let path: StoragePath = StoragePath::unix_root();
let path: StoragePath = path.make_folder().to_path();
assert_eq!(path.as_str(), "/");
let path: StoragePath = path.with_appended("folder.txt").make_folder().to_path();
assert_eq!(path.as_str(), "/folder.txt/");
}
}