Struct radicle_surf::file_system::Path[][src]

pub struct Path(pub NonEmpty<Label>);

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.

Implementations

impl Path[src]

pub fn new(label: Label) -> Path[src]

Create a new Path with a single Label.

pub fn root() -> Self[src]

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());

pub fn is_root(&self) -> bool[src]

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());

pub fn append(&mut self, path: Self)[src]

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);

pub fn push(&mut self, label: Label)[src]

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"));

pub fn pop(&mut self) -> Option<Label>[src]

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")));

pub fn iter(&self) -> impl Iterator<Item = &Label>[src]

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")));

pub fn split_first(&self) -> (&Label, &[Label])[src]

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")][..])
);

pub fn split_last(self) -> (Vec<Label>, Label)[src]

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"))
);

pub fn from_labels(root: Label, labels: &[Label]) -> Path[src]

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")]
);

pub fn with_root(labels: &[Label]) -> Path[src]

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

impl Clone for Path[src]

impl Debug for Path[src]

impl Display for Path[src]

impl Eq for Path[src]

impl FromStr for Path[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for Path[src]

impl IntoCString for Path[src]

impl PartialEq<Path> for Path[src]

impl StructuralEq for Path[src]

impl StructuralPartialEq for Path[src]

impl TryFrom<&'_ str> for Path[src]

type Error = Error

The type returned in the event of a conversion error.

impl TryFrom<PathBuf> for Path[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Path

impl Send for Path

impl Sync for Path

impl Unpin for Path

impl UnwindSafe for Path

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.