Struct netidx_core::path::Path [−][src]
pub struct Path(_);
Expand description
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
returns true if the path starts with /, false otherwise
true if this path is a parent to the specified path. A path is it’s own parent.
Examples
use netidx_core::path::Path;
assert!(Path::is_parent("/", "/foo/bar/baz"));
assert!(Path::is_parent("/foo/bar", "/foo/bar/baz"));
assert!(!Path::is_parent("/foo/bar", "/foo/bareth/bazeth"));
assert!(Path::is_parent("/foo/bar", "/foo/bar"));
finds the longest common parent of the two specified paths, / in the case they are completely disjoint.
This will escape the path seperator and the escape character
in a path part. If you want to be sure that e.g. append
will
only append 1 level, then you should call this function on
your part before appending it.
Examples
use netidx_core::path::Path;
assert_eq!("foo\\/bar", &*Path::escape("foo/bar"));
assert_eq!("\\\\hello world", &*Path::escape("\\hello world"));
This will unescape the path seperator and the escape character in a path part.
Examples
use netidx_core::path::Path;
assert_eq!("foo/bar", &*Path::unescape("foo\\/bar"));
assert_eq!("\\hello world", &*Path::unescape("\\\\hello world"));
return a new path with the specified string appended as a new part separated by the pathsep char.
Examples
use netidx_core::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");
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_core::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"]);
Return an iterator over all the dirnames in the path starting from the root and ending with the entire path.
Examples
use netidx_core::path::Path;
let p = Path::from("/some/path/ending/in/foo");
let mut bn = Path::dirnames(&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);
Return the number of levels in the path.
Examples
use netidx_core::path::Path;
let p = Path::from("/foo/bar/baz");
assert_eq!(Path::levels(&p), 3);
return the path without the last part, or return None if the path is empty or /.
Examples
use netidx_core::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);
return the last part of the path, or return None if the path is empty.
Examples
use netidx_core::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);
return the position of the last path separator in the path, or None if there isn’t one.
Examples
use netidx_core::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);
return the position of the first path separator in the path, or None if there isn’t one.
Examples
use netidx_core::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
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Path
impl UnwindSafe for Path
Blanket Implementations
Mutably borrows from an owned value. Read more