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 /

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

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

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

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. 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.