1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mod components;

pub use components::*;

use crate::{private, Encoding, Utf8Encoding, Utf8Path, Utf8PathBuf, WindowsEncoding};
use std::{fmt, hash::Hasher};

/// Represents a Windows-specific [`Utf8Path`]
pub type Utf8WindowsPath = Utf8Path<Utf8WindowsEncoding>;

/// Represents a Windows-specific [`Utf8PathBuf`]
pub type Utf8WindowsPathBuf = Utf8PathBuf<Utf8WindowsEncoding>;

/// Represents a Windows-specific [`Utf8Encoding`]
pub struct Utf8WindowsEncoding;

impl private::Sealed for Utf8WindowsEncoding {}

impl<'a> Utf8Encoding<'a> for Utf8WindowsEncoding {
    type Components = Utf8WindowsComponents<'a>;

    fn label() -> &'static str {
        "windows"
    }

    fn components(path: &'a str) -> Self::Components {
        Utf8WindowsComponents::new(path)
    }

    fn hash<H: Hasher>(path: &str, h: &mut H) {
        WindowsEncoding::hash(path.as_bytes(), h);
    }

    fn push(current_path: &mut String, path: &str) {
        unsafe {
            WindowsEncoding::push(current_path.as_mut_vec(), path.as_bytes());
        }
    }
}

impl fmt::Debug for Utf8WindowsEncoding {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("Utf8WindowsEncoding").finish()
    }
}

impl fmt::Display for Utf8WindowsEncoding {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "Utf8WindowsEncoding")
    }
}