use crate::error::PathError;
use std::borrow::Cow;
use std::path::Path;
pub fn path_to_utf8(path: &Path) -> Result<&str, PathError> {
path.to_str().ok_or(PathError::NotUtf8)
}
pub fn path_to_string_lossy(path: &Path) -> Cow<'_, str> {
path.to_string_lossy()
}
#[cfg(feature = "unicode")]
pub fn logical_path_key(path: &Path) -> String {
use unicode_normalization::UnicodeNormalization;
path.to_string_lossy().nfc().collect::<String>()
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::Path;
#[test]
fn utf8_ok() {
assert_eq!(path_to_utf8(Path::new("foo/bar")).unwrap(), "foo/bar");
}
}