From c8c9230dd2c2b981fbc90ff587b41b7342b72480 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 27 May 2019 23:33:23 +0800 Subject: Add more helper func in Cursor --- crates/ra_tt/src/buffer.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'crates/ra_tt') diff --git a/crates/ra_tt/src/buffer.rs b/crates/ra_tt/src/buffer.rs index 56b844b8b..940f2b807 100644 --- a/crates/ra_tt/src/buffer.rs +++ b/crates/ra_tt/src/buffer.rs @@ -166,4 +166,19 @@ impl<'a> Cursor<'a> { Cursor::create(self.buffer, EntryPtr(self.ptr.0, self.ptr.1 + 1)) } } + + /// Bump the cursor, if it is a subtree, returns + /// a cursor into that subtree + pub fn bump_subtree(self) -> Cursor<'a> { + match self.entry() { + Some(Entry::Subtree(_, _)) => self.subtree().unwrap(), + _ => self.bump(), + } + } + + /// Check whether it is a top level + pub fn is_root(&self) -> bool { + let entry_id = self.ptr.0; + return entry_id.0 == 0; + } } -- cgit v1.2.3