pub struct Path(pub NonEmpty<Label>);
Expand description

A non-empty set of Labels to define a path to a directory or file.

Path tends to be used for insertion or find operations.

Tuple Fields

0: NonEmpty<Label>

Implementations

Create a new Path with a single Label.

The root path is a Path made up of the single root label (see: Label::root.

Examples
use radicle_surf::file_system::{Label, Path};

let root = Path::root();
assert_eq!(*root.split_first().0, Label::root());

Check that this is the root path.

Examples
use radicle_surf::file_system::Path;
use radicle_surf::file_system::unsound;
use std::convert::TryFrom;

let root = Path::root();
let not_root = unsound::path::new("src/lib.rs");

assert!(root.is_root());
assert!(!not_root.is_root());

Append two Paths together.

Examples
use radicle_surf::file_system::Path;
use radicle_surf::file_system::unsound;
use std::convert::TryFrom;

let mut path1 = unsound::path::new("foo/bar");
let path2 = unsound::path::new("baz/quux");
path1.append(path2);
let expected = unsound::path::new("foo/bar/baz/quux");
assert_eq!(path1, expected);

Push a new Label onto the Path.

Examples
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let mut root = Path::root();
root.push(unsound::label::new("src"));
root.push(unsound::label::new("lib.rs"));

assert_eq!(root, unsound::path::new("~/src/lib.rs"));

Pop the Label from the end of the tail.

Examples
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let mut root = Path::root();
root.push(unsound::label::new("src"));
root.push(unsound::label::new("lib.rs"));

assert_eq!(root.pop(), Some(unsound::label::new("lib.rs")));

Iterator over the Labels in the Path.

Examples
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let path = unsound::path::new("~/src/lib.rs");
let mut path_iter = path.iter();

assert_eq!(path_iter.next(), Some(&Label::root()));
assert_eq!(path_iter.next(), Some(&unsound::label::new("src")));
assert_eq!(path_iter.next(), Some(&unsound::label::new("lib.rs")));

Get the first Label in the Path and the rest of the Labels after it.

Examples
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let path = unsound::path::new("~/src/lib.rs");

assert_eq!(
    path.split_first(),
    (&Label::root(), &[unsound::label::new("src"), unsound::label::new("lib.rs")][..])
);

Get the prefix of the Labels and the last Label.

This is useful when the prefix is a directory path and the last label is a file name.

Examples
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let path = unsound::path::new("~/src/lib.rs");
assert_eq!(path.split_last(), (vec![Label::root(), unsound::label::new("src")], unsound::label::new("lib.rs")));
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let path = unsound::path::new("foo/bar/baz");
assert_eq!(
    path.split_last(),
    (vec![unsound::label::new("foo"), unsound::label::new("bar")], unsound::label::new("baz"))
);

Construct a Path given at least one Label followed by 0 or more Labels.

Examples
use nonempty::NonEmpty;
use radicle_surf::file_system::{Path, Label};
use radicle_surf::file_system::unsound;

let path = Path::from_labels(
    Label::root(),
    &[unsound::label::new("foo"), unsound::label::new("bar"), unsound::label::new("baz.rs")]
);

let mut expected = Path::root();
expected.push(unsound::label::new("foo"));
expected.push(unsound::label::new("bar"));
expected.push(unsound::label::new("baz.rs"));

assert_eq!(path, expected);
let path_vec: Vec<Label> = path.0.into();
assert_eq!(
    path_vec,
    vec![Label::root(), unsound::label::new("foo"), unsound::label::new("bar"),
    unsound::label::new("baz.rs")]
);

Construct a Path using Label::root as the head of the `Path.

Examples
use nonempty::NonEmpty;
use radicle_surf::file_system::{Label, Path};
use radicle_surf::file_system::unsound;

let path = Path::with_root(
    &[unsound::label::new("foo"), unsound::label::new("bar"), unsound::label::new("baz.rs")]
);

let mut expected = Path::root();
expected.push(unsound::label::new("foo"));
expected.push(unsound::label::new("bar"));
expected.push(unsound::label::new("baz.rs"));

assert_eq!(path, expected);
let path_vec: Vec<Label> = path.0.into();
assert_eq!(
    path_vec,
    vec![Label::root(), unsound::label::new("foo"), unsound::label::new("bar"),
    unsound::label::new("baz.rs")]
);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Consume this container, converting it into a CString

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.