-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stripped down unix path (vercel/turborepo#4767)
### Description - Experiment with a very stripped down `RelativeUnixPath` implementation - Test out using it in `git.rs` ### Testing Instructions Existing tests in `git.rs`
- Loading branch information
Greg Soltis
authored
May 4, 2023
1 parent
57d561a
commit d446153
Showing
6 changed files
with
71 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use std::path::Path; | ||
|
||
use crate::{IntoSystem, PathError, PathValidationError, RelativeSystemPathBuf}; | ||
|
||
pub struct RelativeUnixPath { | ||
inner: Path, | ||
} | ||
|
||
impl RelativeUnixPath { | ||
pub fn new<P: AsRef<Path>>(value: &P) -> Result<&Self, PathError> { | ||
let path = value.as_ref(); | ||
if path.is_absolute() { | ||
return Err(PathValidationError::NotRelative(path.to_owned()).into()); | ||
} | ||
// copied from stdlib path.rs: relies on the representation of | ||
// RelativeUnixPath being just a Path, the same way Path relies on | ||
// just being an OsStr | ||
Ok(unsafe { &*(path as *const Path as *const Self) }) | ||
} | ||
|
||
pub fn to_system_path(&self) -> Result<RelativeSystemPathBuf, PathError> { | ||
let system_path = self.inner.into_system()?; | ||
Ok(RelativeSystemPathBuf::new_unchecked(system_path)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters