types: add explicit conversions from owned paths types to unsized ref

Summary:
There are scenarios where an &PathComponentBuf or a &RepoPath will show up.
An example when using get from a HashMap. These are not the references that we
are looking for. We want &PathComponent and &RepoPath respectively. Adding
explicit conversions.

(Note: this ignores all push blocking failures!)

Reviewed By: quark-zju

Differential Revision: D14292711

fbshipit-source-id: 29f4de25c2ffebf7f009e4f2515e0ba8f0371ae0
This commit is contained in:
Stefan Filip 2019-03-05 16:08:15 -08:00 committed by Facebook Github Bot
parent 765659d505
commit 43fb573c23

View File

@ -89,6 +89,11 @@ impl RepoPathBuf {
Ok(RepoPathBuf(s))
}
/// Converts the `RepoPathBuf` in a `RepoPath`.
pub fn as_repo_path(&self) -> &RepoPath {
self
}
/// Returns whether the current `RepoPathBuf` has no components. Since `RepoPathBuf`
/// represents the relative path from the start of the repository this is equivalent to
/// checking whether the path is the root of the repository
@ -276,6 +281,11 @@ impl PathComponentBuf {
Ok(PathComponentBuf(s))
}
/// Converts the `PathComponentBuf` in a `PathComponent`.
pub fn as_path_component(&self) -> &PathComponent {
self
}
fn from_string_unchecked(s: String) -> Self {
PathComponentBuf(s)
}