Skip to main content

file_storage/path/mutate/
append_char.rs

1use crate::StoragePath;
2
3impl StoragePath {
4    //! Append Char
5
6    /// Appends the char.
7    pub fn append_char(&mut self, c: char) {
8        unsafe { self.path_mut() }.push(c);
9    }
10
11    /// Appends the char.
12    pub fn with_appended_char(mut self, c: char) -> Self {
13        self.append_char(c);
14        self
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use crate::StoragePath;
21
22    #[test]
23    fn append() {
24        let path: StoragePath = StoragePath::unix_root();
25        let result: StoragePath = path.with_appended_char('c');
26        assert_eq!(result.as_str(), "/c");
27
28        let file: StoragePath = StoragePath::unix_root().with_appended("file");
29        let result: StoragePath = file.with_appended_char('c');
30        assert_eq!(result.as_str(), "/filec");
31
32        let folder_path: StoragePath = StoragePath::unix_root().with_appended("folder/");
33        let result: StoragePath = folder_path.with_appended_char('c');
34        assert_eq!(result.as_str(), "/folder/c");
35    }
36}