[][src]Struct namespace::Namespace

pub struct Namespace {
    pub s: String,
    pub segments: Vec<usize>,
}

Namespace cannot be empty. It always contains at least one segment.

Fields

s: Stringsegments: Vec<usize>

Methods

impl Namespace[src]

pub fn new(s: &str) -> Result<Self, NSErr>[src]

let ns = Namespace::new("a::b::c").unwrap();

pub fn len(&self) -> usize[src]

Returns the number of segments.

pub fn append(&self, other: &Namespace) -> Namespace[src]

Appends a new namespace to the end of Self. For example,

let ns1 = Namespace::new("a::b").unwrap();
let ns2 = Namespace::new("b::c").unwrap();
let ns = ns1.append(&ns2);

assert!(ns, "a::b::b::c");

pub fn append_at(&self, other: &Namespace, n: usize) -> Result<Namespace, NSErr>[src]

Appends a new namespace at index. Returns an error if the n > self.len().

let ns1 = Namespace::new("a::b::c").unwrap();
let ns2 = Namespace::new("d").unwrap();
assert_eq!(ns1.append_at(&ns2, 1), "a::d");

pub fn remove(&self, n: usize) -> Result<Namespace, NSErr>[src]

Remove n segments from the right-hand side of Self. Namespaces cannot be empty so returns an error if all segments are removed.

assert_eq!(
    Namespace::new("a::b::c").unwrap()
        .remove(2)
        .unwrap()
        .to_string(),
    "a"
);

pub fn truncate(&self, n: usize) -> Result<Namespace, NSErr>[src]

Truncate the namespace to the first n segments. In other words truncate to length n. Returns an error if n > self.len().

pub fn sliding_match(&self, other: &Namespace) -> Vec<isize>[src]

Tries to find a sliding match. Returns the index of the position in self aligned to the first segment of other. Note that this value can be negative. If there are no matches returns an empty Vec.

let ns1 = Namespace::new("a::b::c").unwrap();
let ns2 = Namespace::new("c::d").unwrap();
assert_eq!(
    ns1.sliding_match(&ns),
    vec!(2)
);

pub fn offset_match(&self, other: &Namespace, offset: isize) -> bool[src]

The offset is the index of the position in self aligned to the first segment of other. Returns true if all aligned segments match.

pub fn remainder(&self, other: &Namespace) -> Result<Namespace, NSErr>[src]

Returns the remainder of other. If there is no match, multiple matches or no remainder, returns an error.

let ns1 = Namespace::new("a::b::c").unwrap();
let ns2 = Namespace::new("c::d::e").unwrap();
assert_eq!(
    ns.remainder(&ns2).unwrap().to_string(),
    "d::e"
);

pub fn sliding_join(&self, other: &Namespace) -> Result<Namespace, NSErr>[src]

If there is a unique sliding_match, returns self appended with the the remainder of other, otherwise returns an error.

let ns = Namespace::new("a::b").unwrap();
let other = Namespace::new("b::c").unwrap();
ns.sliding_join(&other);
assert_eq!(
    ns.sliding_join(&other).unwrap().to_string(),
    "a::b::c",
);

Important traits for NamespaceIter<'a>
pub fn iter(&self) -> NamespaceIter[src]

Trait Implementations

impl Clone for Namespace[src]

impl Eq for Namespace[src]

impl PartialEq<Namespace> for Namespace[src]

impl Display for Namespace[src]

impl Debug for Namespace[src]

impl Index<usize> for Namespace[src]

type Output = str

The returned type after indexing.

impl Hash for Namespace[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> From<T> for 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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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