[][src]Struct netidx::path::Path

pub struct Path(_);

A path in the namespace. Paths are immutable and reference counted. Path components are seperated by /, which may be escaped with . / and \ are the only special characters in path, any other unicode character may be used. Path lengths are not limited on the local machine, but may be restricted by maximum message size on the wire.

Implementations

impl Path[src]

pub fn as_chars(self) -> Chars[src]

pub fn root() -> Path[src]

returns /

pub fn is_absolute<T: AsRef<str>>(p: T) -> bool[src]

returns true if the path starts with /, false otherwise

pub fn append<T: AsRef<str>>(&self, other: T) -> Self[src]

return a new path with the specified string appended as a new part separated by the pathsep char.

Examples

use netidx::path::Path;
let p = Path::root().append("bar").append("baz");
assert_eq!(&*p, "/bar/baz");

let p = Path::root().append("/bar").append("//baz//////foo/");
assert_eq!(&*p, "/bar/baz/foo");

pub fn parts(s: &str) -> impl Iterator<Item = &str>[src]

return an iterator over the parts of the path. The path separator may be escaped with . and a literal \ may be represented as \.

Examples

use netidx::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::parts(&p).collect::<Vec<_>>(), vec!["foo", "bar", "baz"]);

let p = Path::from(r"/foo\/bar/baz");
assert_eq!(Path::parts(&p).collect::<Vec<_>>(), vec![r"foo\/bar", "baz"]);

let p = Path::from(r"/foo\\/bar/baz");
assert_eq!(Path::parts(&p).collect::<Vec<_>>(), vec![r"foo\\", "bar", "baz"]);

let p = Path::from(r"/foo\\\/bar/baz");
assert_eq!(Path::parts(&p).collect::<Vec<_>>(), vec![r"foo\\\/bar", "baz"]);

pub fn basenames(s: &str) -> impl Iterator<Item = &str>[src]

Return an iterator over all the basenames in the path starting from the root and ending with the entire path.

Examples

use netidx::path::Path;
let p = Path::from("/some/path/ending/in/foo");
let mut bn = Path::basenames(&p);
assert_eq!(bn.next(), Some("/"));
assert_eq!(bn.next(), Some("/some"));
assert_eq!(bn.next(), Some("/some/path"));
assert_eq!(bn.next(), Some("/some/path/ending"));
assert_eq!(bn.next(), Some("/some/path/ending/in"));
assert_eq!(bn.next(), Some("/some/path/ending/in/foo"));
assert_eq!(bn.next(), None);

pub fn levels(s: &str) -> usize[src]

Return the number of levels in the path.

Examples

use netidx::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::levels(&p), 3);

pub fn dirname(s: &str) -> Option<&str>[src]

return the path without the last part, or return None if the path is empty or /.

Examples

use netidx::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::dirname(&p), Some("/foo/bar"));

let p = Path::root();
assert_eq!(Path::dirname(&p), None);

let p = Path::from("/foo");
assert_eq!(Path::dirname(&p), None);

pub fn basename(s: &str) -> Option<&str>[src]

return the last part of the path, or return None if the path is empty.

Examples

use netidx::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::basename(&p), Some("baz"));

let p = Path::from("foo");
assert_eq!(Path::basename(&p), Some("foo"));

let p = Path::from("foo/bar");
assert_eq!(Path::basename(&p), Some("bar"));

let p = Path::from("");
assert_eq!(Path::basename(&p), None);

let p = Path::from("/");
assert_eq!(Path::basename(&p), None);

pub fn rfind_sep(s: &str) -> Option<usize>[src]

return the position of the last path separator in the path, or None if there isn't one.

Examples

use netidx::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::rfind_sep(&p), Some(8));

let p = Path::from("");
assert_eq!(Path::rfind_sep(&p), None);

pub fn find_sep(s: &str) -> Option<usize>[src]

return the position of the first path separator in the path, or None if there isn't one.

Examples

use netidx::path::Path;
let p = Path::from("foo/bar/baz");
assert_eq!(Path::find_sep(&p), Some(3));

let p = Path::from("");
assert_eq!(Path::find_sep(&p), None);

Trait Implementations

impl AsRef<str> for Path[src]

impl Borrow<str> for Path[src]

impl Clone for Path[src]

impl Debug for Path[src]

impl Deref for Path[src]

type Target = str

The resulting type after dereferencing.

impl Display for Path[src]

impl Eq for Path[src]

impl<'a> From<&'a String> for Path[src]

impl From<&'static str> for Path[src]

impl From<Chars> for Path[src]

impl From<String> 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 Ord for Path[src]

impl PartialEq<Path> for Path[src]

impl PartialOrd<Path> for Path[src]

impl StructuralEq for Path[src]

impl StructuralPartialEq for Path[src]

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> From<T> for T[src]

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

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

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