diff --git a/src/lib.rs b/src/lib.rs index 80f045b..b1679b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -677,6 +677,7 @@ impl Ord for ArrayVec where A::Item: Ord { } } +/// `Write` appends written data to the end of the vector. impl> io::Write for ArrayVec { fn write(&mut self, data: &[u8]) -> io::Result { unsafe { diff --git a/tests/tests.rs b/tests/tests.rs index 1f7ff3d..ac3782f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -249,3 +249,14 @@ fn test_into_inner_3_() { v.extend(1..); assert_eq!(v.into_inner().unwrap(), [1, 2, 3, 4]); } + +#[test] +fn test_write() { + use std::io::Write; + let mut v = ArrayVec::<[_; 8]>::new(); + write!(&mut v, "\x01\x02\x03").unwrap(); + assert_eq!(&v[..], &[1, 2, 3]); + let r = v.write(&[9; 16]).unwrap(); + assert_eq!(r, 5); + assert_eq!(&v[..], &[1, 2, 3, 9, 9, 9, 9, 9]); +}