From 90196107284717ca99753660a4e7e20fff1e10fb Mon Sep 17 00:00:00 2001 From: debris Date: Mon, 30 Nov 2015 19:14:46 +0100 Subject: [PATCH] NibbleSlice mid do not share lifetime with a parent view, but with a collection --- src/nibbleslice.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nibbleslice.rs b/src/nibbleslice.rs index 6ccf695c0..e7e62e193 100644 --- a/src/nibbleslice.rs +++ b/src/nibbleslice.rs @@ -31,7 +31,7 @@ pub struct NibbleSlice<'a> { offset: usize, } -impl<'a> NibbleSlice<'a> { +impl<'a, 'view> NibbleSlice<'a> where 'a: 'view { /// Create a new nibble slice with the given byte-slice. pub fn new(data: &[u8]) -> NibbleSlice { NibbleSlice::new_offset(data, 0) } @@ -60,7 +60,7 @@ impl<'a> NibbleSlice<'a> { } /// Return object which represents a view on to this slice (further) offset by `i` nibbles. - pub fn mid(&self, i: usize) -> Self { NibbleSlice{ data: self.data, offset: self.offset + i} } + pub fn mid(&'view self, i: usize) -> NibbleSlice<'a> { NibbleSlice{ data: self.data, offset: self.offset + i} } /// Do we start with the same nibbles as the whole of `them`? pub fn starts_with(&self, them: &Self) -> bool { self.common_prefix(them) == them.len() } @@ -192,4 +192,4 @@ mod tests { assert!(n >= m.mid(4)); assert!(n <= m.mid(4)); } -} \ No newline at end of file +}