Merge pull request #12 from tbu-/pr_write
Add `io::Write` implementation akin to `Vec`
This commit is contained in:
+17
@@ -2,6 +2,7 @@ extern crate odds;
|
|||||||
extern crate nodrop;
|
extern crate nodrop;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::io;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
@@ -675,3 +676,19 @@ impl<A: Array> Ord for ArrayVec<A> where A::Item: Ord {
|
|||||||
(**self).cmp(other)
|
(**self).cmp(other)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A: Array<Item=u8>> io::Write for ArrayVec<A> {
|
||||||
|
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
|
||||||
|
unsafe {
|
||||||
|
let len = self.len();
|
||||||
|
let mut tail = slice::from_raw_parts_mut(self.get_unchecked_mut(len),
|
||||||
|
A::capacity() - len);
|
||||||
|
let result = tail.write(data);
|
||||||
|
if let Ok(written) = result {
|
||||||
|
self.set_len(len + written);
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn flush(&mut self) -> io::Result<()> { Ok(()) }
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user