[−][src]Crate normpath
This crate provides methods to normalize paths in the recommended way for the operating system.
It was made to fix a recurring bug caused by using fs::canonicalize
on
Windows: #45067, #48249, #52440, #55812, #58613, #59107,
#74327. Normalization is usually a better choice unless you specifically
need a canonical path.
Using these replacement methods will usually fix those issues, but see their documentation for more information:
PathExt::normalize
(usually replacesPath::canonicalize
)BasePath::join
(replacesPath::join
)BasePath::parent
(replacesPath::parent
)BasePathBuf::pop
(replacesPathBuf::pop
)BasePathBuf::push
(replacesPathBuf::push
)
Sponsorship
If this crate has been useful for your project, let me know with a sponsorship! Sponsorships help me create and maintain my open source libraries, and they are always very appreciated.
Examples
use std::io; use std::path::Path; use normpath::BasePathBuf; use normpath::PathExt; fn find_target_dir(path: &Path) -> io::Result<Option<BasePathBuf>> { let mut path = path.normalize()?; while !path.ends_with("target") { match path.pop() { Ok(true) => continue, Ok(false) => {} Err(_) => { eprintln!("Some components could not be normalized."); } } return Ok(None); } Ok(Some(path)) }
Modules
error | The error types defined by this crate. |
Structs
BasePath | A path that has a prefix on Windows. |
BasePathBuf | An owned |
Traits
PathExt | Additional methods added to |