pub struct RepoPath { /* private fields */ }Expand description
Borrowed repository path.
Implementations§
Source§impl RepoPath
impl RepoPath
Sourcepub fn from_internal_string(
value: &str,
) -> Result<&RepoPath, InvalidNewRepoPathError>
pub fn from_internal_string( value: &str, ) -> Result<&RepoPath, InvalidNewRepoPathError>
Wraps valid string representation as RepoPath.
Returns an error if the input value contains empty path component. For
example, "/", "/foo", "foo/", "foo//bar" are all invalid.
Sourcepub fn to_internal_dir_string(&self) -> String
pub fn to_internal_dir_string(&self) -> String
The full string form used internally, not for presenting to users (where we may want to use the platform’s separator). This format includes a trailing slash, unless this path represents the root directory. That way it can be concatenated with a basename and produce a valid path.
Sourcepub fn as_internal_file_string(&self) -> &str
pub fn as_internal_file_string(&self) -> &str
The full string form used internally, not for presenting to users (where we may want to use the platform’s separator).
Sourcepub fn to_fs_path(&self, base: &Path) -> Result<PathBuf, InvalidRepoPathError>
pub fn to_fs_path(&self, base: &Path) -> Result<PathBuf, InvalidRepoPathError>
Converts repository path to filesystem path relative to the base.
The returned path should never contain .., C: (on Windows), etc.
However, it may contain reserved working-copy directories such as .jj.
Sourcepub fn to_fs_path_unchecked(&self, base: &Path) -> PathBuf
pub fn to_fs_path_unchecked(&self, base: &Path) -> PathBuf
Converts repository path to filesystem path relative to the base,
without checking invalid path components.
The returned path may point outside of the base directory. Use this
function only for displaying or testing purposes.
Sourcepub fn starts_with(&self, base: &RepoPath) -> bool
pub fn starts_with(&self, base: &RepoPath) -> bool
Returns true if the base is a prefix of this path.
Sourcepub fn strip_prefix(&self, base: &RepoPath) -> Option<&RepoPath>
pub fn strip_prefix(&self, base: &RepoPath) -> Option<&RepoPath>
Returns the remaining path with the base path removed.
Sourcepub fn parent(&self) -> Option<&RepoPath>
pub fn parent(&self) -> Option<&RepoPath>
Returns the parent path without the base name component.
Sourcepub fn split(&self) -> Option<(&RepoPath, &RepoPathComponent)>
pub fn split(&self) -> Option<(&RepoPath, &RepoPathComponent)>
Splits this into the parent path and base name component.
Sourcepub fn components(&self) -> RepoPathComponentsIter<'_> ⓘ
pub fn components(&self) -> RepoPathComponentsIter<'_> ⓘ
Iterator over the path’s components, with parents before children.
For example, RepoPath::from_internal_string("a/b/c")?.components()
yields “a”, “b”, “c”.
Sourcepub fn ancestors(&self) -> impl Iterator<Item = &RepoPath>
pub fn ancestors(&self) -> impl Iterator<Item = &RepoPath>
Iterator over the path’s ancestors, with children before parents.
For example, RepoPath::from_internal_string("a/b/c")?.ancestors()
yiels “a/b/c”, “a/b”, “a”, “”.
Sourcepub fn join(&self, entry: &RepoPathComponent) -> RepoPathBuf
pub fn join(&self, entry: &RepoPathComponent) -> RepoPathBuf
Join the given entry on the Path returning a new RepoPathBuf.
Sourcepub fn split_common_prefix(&self, other: &RepoPath) -> (&RepoPath, &RepoPath)
pub fn split_common_prefix(&self, other: &RepoPath) -> (&RepoPath, &RepoPath)
Splits this path at its common prefix with other.
§Returns
Returns the (common_prefix, self_remainder).
All paths will at least have RepoPath::root() as a common prefix,
therefore even if self and other have no matching parent component
this function will always return at least (RepoPath::root(), self).
§Examples
use jj_core::repo_path::RepoPath;
let bing_path = RepoPath::from_internal_string("foo/bar/bing").unwrap();
let baz_path = RepoPath::from_internal_string("foo/bar/baz").unwrap();
let foo_bar_path = RepoPath::from_internal_string("foo/bar").unwrap();
assert_eq!(
bing_path.split_common_prefix(&baz_path),
(foo_bar_path, RepoPath::from_internal_string("bing").unwrap())
);
let unrelated_path = RepoPath::from_internal_string("no/common/prefix").unwrap();
assert_eq!(
baz_path.split_common_prefix(&unrelated_path),
(RepoPath::root(), baz_path)
);Trait Implementations§
Source§impl AsRef<RepoPath> for RepoPathBuf
impl AsRef<RepoPath> for RepoPathBuf
Source§impl Borrow<RepoPath> for RepoPathBuf
impl Borrow<RepoPath> for RepoPathBuf
Source§impl ContentHash for RepoPath
impl ContentHash for RepoPath
impl Eq for RepoPath
Source§impl PartialOrd for RepoPath
impl PartialOrd for RepoPath
Source§impl Serialize for RepoPath
impl Serialize for RepoPath
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for RepoPath
Auto Trait Implementations§
impl !Sized for RepoPath
impl Freeze for RepoPath
impl RefUnwindSafe for RepoPath
impl Send for RepoPath
impl Sync for RepoPath
impl Unpin for RepoPath
impl UnsafeUnpin for RepoPath
impl UnwindSafe for RepoPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.