pub struct Utf8Paths0 { /* private fields */ }
Expand description
A store for null-separated paths.
This manages paths on Unix and Windows platforms, including converting /
on Windows to \
.
§Null-separated paths
Paths as produced by tools like git diff --name-only
are typically separated by newline
characters (\n
). However, on Unix platforms filenames can themselves have newlines embedded in
them, so source control systems often end up quoting newlines and other “unusual”
characters.
A robust, lossless way to retrieve a list of paths is by separating them with null characters. Both Unix and Windows platforms guarantee that a path can never have embedded null characters.
§Examples
Most source control systems can provide null-separated paths. These examples are expected to be run from the Cargo workspace root (which is assumed to be the same as the repository root).
In most cases, you’ll want to compare the current working directory against the merge
base, or nearest/greatest/lowest common
ancestor, of the current commit with a
specified upstream revision, such as origin/main
. To do so, run:
- Git:
git diff -z --name-only $(git merge-base <upstream rev> HEAD)
- Mercurial:
hg status --print0 -mard --no-status --rev 'ancestor(<upstream rev>,.)'
NOTE:
- The
$()
syntax in Bash and other shells means “run the command and insert its contents here”. - Git provides a syntax
<upstream rev>...
which purports to use the merge base, but it ignores uncommitted changes. Executinggit merge-base
as a separate command is the only way to include uncommitted changes. - The
-mard
flag tohg status
means that untracked files are not included.git diff
does not have an option to display untracked files. For more discussion, see the documentation foradd_changed_paths
.
In general, to obtain a list of changed paths between two revisions (omit <new rev>
if
comparing against the working directory):
- Git:
git diff -z --name-only <old rev> <new rev>
- Mercurial:
hg status --print0 -mard --no-status <old rev> <new rev>
To obtain a list of all files in the working directory that are tracked by the source control system:
- Git:
git ls-files -z
- Mercurial:
hg files --print0
Null-separated paths are produced through the -z
option to Git commands, or the --print0
option to Mercurial. If you’re using a different system, check its help for instructions.
§Implementations
&'a Utf8Paths0
implements IntoIterator<Item = &'a Utf8Path>
.
Implementations§
Source§impl Utf8Paths0
impl Utf8Paths0
Sourcepub fn new(buf: impl Into<String>) -> Self
pub fn new(buf: impl Into<String>) -> Self
Creates a new instance of Utf8Paths0
from a string with embedded nulls.
The string may, but does not need to, have a trailing null byte.
Sourcepub fn from_bytes(buf: impl Into<Vec<u8>>) -> Result<Self, (Vec<u8>, Utf8Error)>
pub fn from_bytes(buf: impl Into<Vec<u8>>) -> Result<Self, (Vec<u8>, Utf8Error)>
Creates a new instance of Utf8Paths0
from a Vec<u8>
, performing a UTF-8 validation
check on the buffer.
The buffer may, but does not need to, have a trailing null byte.
§Errors
If any paths inside the string weren’t valid UTF-8, this returns the first path that failed to parse and the error returned.
Sourcepub fn new_forward_slashes(buf: impl Into<String>) -> Self
pub fn new_forward_slashes(buf: impl Into<String>) -> Self
Creates a new instance of Utf8Paths0
, converting /
to \
on platforms like Windows.
Some tools like Git (but not Mercurial) return paths with /
on Windows, even though the
canonical separator on the platform is \
. This constructor changes all instances of /
to \
.
Trait Implementations§
Source§impl Clone for Utf8Paths0
impl Clone for Utf8Paths0
Source§fn clone(&self) -> Utf8Paths0
fn clone(&self) -> Utf8Paths0
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for Utf8Paths0
impl Debug for Utf8Paths0
Source§impl<'a> IntoIterator for &'a Utf8Paths0
impl<'a> IntoIterator for &'a Utf8Paths0
Source§impl Ord for Utf8Paths0
impl Ord for Utf8Paths0
Source§fn cmp(&self, other: &Utf8Paths0) -> Ordering
fn cmp(&self, other: &Utf8Paths0) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Utf8Paths0
impl PartialEq for Utf8Paths0
Source§impl PartialOrd for Utf8Paths0
impl PartialOrd for Utf8Paths0
impl Eq for Utf8Paths0
impl StructuralPartialEq for Utf8Paths0
Auto Trait Implementations§
impl Freeze for Utf8Paths0
impl RefUnwindSafe for Utf8Paths0
impl Send for Utf8Paths0
impl Sync for Utf8Paths0
impl Unpin for Utf8Paths0
impl UnwindSafe for Utf8Paths0
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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§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.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.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more