determinator

Struct Utf8Paths0

Source
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. Executing git merge-base as a separate command is the only way to include uncommitted changes.
  • The -mard flag to hg 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 for add_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

Source

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.

Source

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.

Source

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 \.

Source

pub fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = &'a Utf8Path> + 'a>

Iterates over the paths in this buffer.

Trait Implementations§

Source§

impl Clone for Utf8Paths0

Source§

fn clone(&self) -> Utf8Paths0

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Utf8Paths0

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> IntoIterator for &'a Utf8Paths0

Source§

type Item = &'a Utf8Path

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = &'a Utf8Path> + 'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Utf8Paths0

Source§

fn cmp(&self, other: &Utf8Paths0) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Utf8Paths0

Source§

fn eq(&self, other: &Utf8Paths0) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Utf8Paths0

Source§

fn partial_cmp(&self, other: &Utf8Paths0) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Utf8Paths0

Source§

impl StructuralPartialEq for Utf8Paths0

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V