pub fn adjacent(
        &self,
        tree: &tree::Tree<Id>,
        mut num: i64,
    ) -> Result<StringIndex<Id>, tree::TreeError> {
        {
            if num > 0 && !self.still_exists(tree) {
                // character doesn't exist and we're moving forward; so add one to number so that
                // we resolve the character to its true position
                num += 1;
            }
        }

        let mut i = self.clone();

        while num != 0 {
            if num > 0 {
                i = i.adjacent_next(tree, false)?;
                num -= 1;
            } else {
                i = i.adjacent_next(tree, true)?;
                num += 1;
            }
        }

        Ok(i)
    }
/// Returns the index that is `num` characters away from `self`. If reaches start or end of
/// string, will stop. Takes `O(n)`; make take longer if there are a lot of deleted characters
/// to traverse over.
Returns the index that is `num` characters away from `self`. If reaches start or end of
string, will stop. Takes `O(n)`; make take longer if there are a lot of deleted characters
to traverse over.
Returns the index that is ` num ` characters away from ` self ` . If reaches start or end of string will stop . Takes ` O ( n ) ` ; make take longer if there are a lot of deleted characters to traverse over .
pub fn adjacent(
        &self,
        tree: &tree::Tree<Id>,
        mut num: i64,
    ) -> Result<StringIndex<Id>, tree::TreeError> {
        {
            if num > 0 && !self.still_exists(tree) {
                // character doesn't exist and we're moving forward; so add one to number so that
                // we resolve the character to its true position
                num += 1;
            }
        }
        let mut i = self.clone();
        while num != 0 {
            if num > 0 {
                i = i.adjacent_next(tree, false)?;
                num -= 1;
            } else {
                i = i.adjacent_next(tree, true)?;
                num += 1;
            }
        }
        Ok(i)
    }
pub fn adjacent ( & self , tree : & tree :: Tree < Id > , mut num : i64 , ) -> Result < StringIndex < Id > , tree :: TreeError > { { if num > 0 && ! self . still_exists ( tree ) { // character doesn't exist and we're moving forward; so add one to number so that // we resolve the character to its true position num += 1 ; } } let mut i = self . clone ( ) ; while num != 0 { if num > 0 { i = i . adjacent_next ( tree , false ) ? ; num -= 1 ; } else { i = i . adjacent_next ( tree , true ) ? ; num += 1 ; } } Ok ( i ) }
Returns the index that is `num` characters away from `self`.
Returns the index that is ` num ` characters away from ` self ` .
&self
tree
&tree::Tree<Id>
num
i64