Added ArrayString::from constructor that takes string slice.

Also added corresponding test.
This commit is contained in:
Alexander Regueiro
2016-02-05 22:30:24 +00:00
parent 97df44aa2a
commit 9845491060
2 changed files with 24 additions and 13 deletions
+5 -12
View File
@@ -25,17 +25,6 @@ fn test_simple() {
assert_eq!(sum_len, 8);
}
#[test]
fn test_u16_index() {
const N: usize = 4096;
let mut vec: ArrayVec<[_; N]> = ArrayVec::new();
for _ in 0..N {
assert!(vec.push(1u8).is_none());
}
assert!(vec.push(0).is_some());
assert_eq!(vec.len(), N);
}
#[test]
fn test_iter() {
let mut iter = ArrayVec::from([1, 2, 3]).into_iter();
@@ -288,7 +277,6 @@ fn test_string() {
let tmut: &mut str = &mut t;
assert_eq!(tmut, "ab");
// Test Error trait / try
let t = || -> Result<(), Box<Error>> {
let mut t = ArrayString::<[_; 2]>::new();
@@ -296,4 +284,9 @@ fn test_string() {
Ok(())
}();
assert!(t.is_err());
// Test `from` constructor
let u = ArrayString::<[_; 11]>::from(text).unwrap();
assert_eq!(&u, text);
assert_eq!(u.len(), text.len());
}