Merge pull request #40 from jmesmon/slicebox-deref

SliceBox: allow Deref into &[T]
This commit is contained in:
Ty Overby 2015-05-28 15:09:30 -07:00
commit 84b5c416ca
2 changed files with 15 additions and 0 deletions

View File

@ -322,3 +322,14 @@ impl <'a, T> Deref for RefBox<'a, T> {
}
}
}
impl <'a, T> Deref for SliceBox<'a, T> {
type Target = [T];
fn deref(&self) -> &[T] {
match &self.inner {
&RefBoxInner::Ref(ref t) => t,
&RefBoxInner::Box(ref b) => b.deref()
}
}
}

View File

@ -311,6 +311,10 @@ fn test_slicebox() {
let slice = [1u32, 2, 3 ,4, 5];
let encoded = encode(&SliceBox::new(&slice), Infinite).unwrap();
let decoded: SliceBox<'static, u32> = decode(&encoded[..]).unwrap();
{
let sb: &[u32] = &decoded;
assert!(slice == sb);
}
let vecx: Vec<u32> = decoded.take();
assert!(slice == &vecx[..]);
}