file_storage/path/properties/
len.rs

1use crate::{FilePath, FolderPath, StoragePath};
2
3impl StoragePath {
4    //! Length
5
6    /// Gets the path length. (in bytes)
7    pub fn len(&self) -> usize {
8        self.path().len()
9    }
10
11    /// Checks if the path is empty.
12    pub fn is_empty(&self) -> bool {
13        self.len() == 0
14    }
15}
16
17impl FilePath {
18    //! Length
19
20    /// Gets the path length. (in bytes)
21    pub fn len(&self) -> usize {
22        self.path().len()
23    }
24
25    /// Checks if the path is empty.
26    pub fn is_empty(&self) -> bool {
27        self.len() == 0
28    }
29}
30
31impl FolderPath {
32    //! Length
33
34    /// Gets the path length. (in bytes)
35    pub fn len(&self) -> usize {
36        self.path().len()
37    }
38
39    /// Checks if the path is empty.
40    pub fn is_empty(&self) -> bool {
41        self.len() == 0
42    }
43}
44
45#[cfg(test)]
46mod tests {
47    use crate::StoragePath;
48
49    #[test]
50    fn len() {
51        let path: StoragePath = unsafe { StoragePath::new("/你/好", 1, '/') };
52        assert_eq!(path.len(), 8);
53    }
54}