Skip to main content

file_storage/path/core/
clone.rs

1use crate::{FilePath, FolderPath, StoragePath};
2
3impl StoragePath {
4    //! Clone
5
6    /// Clones the path with the extra capacity.
7    pub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self {
8        let mut path: String = String::with_capacity(self.len() + extra_capacity);
9        path.push_str(self.path());
10        unsafe { Self::new(path, self.base_len(), self.file_separator()) }
11    }
12}
13
14impl FilePath {
15    //! Clone
16
17    /// Clones the path with the extra capacity.
18    pub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self {
19        let path: StoragePath = self.path().clone_with_extra_capacity(extra_capacity);
20        // Safety: the original path is already a file path.
21        unsafe { Self::new(path) }
22    }
23}
24
25impl FolderPath {
26    //! Clone
27
28    /// Clones the path with the extra capacity.
29    pub fn clone_with_extra_capacity(&self, extra_capacity: usize) -> Self {
30        let path: StoragePath = self.path().clone_with_extra_capacity(extra_capacity);
31        // Safety: the original path is already a folder path.
32        unsafe { Self::new(path) }
33    }
34}