[−][src]Struct namespace::Namespace
Namespace
cannot be empty. It always contains at least one segment.
Fields
s: String
segments: 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]
impl Hash for Namespace
[src]
Auto Trait Implementations
impl Send for Namespace
impl Sync for Namespace
impl Unpin for Namespace
impl UnwindSafe for Namespace
impl RefUnwindSafe for Namespace
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,