diff --git a/src/lib.rs b/src/lib.rs index 132a710..439975a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,45 +185,6 @@ where self.0.as_mut() } - /// Convert the given slice into a reference to a hybrid array. - /// - /// # Panics - /// - /// Panics if the slice's length doesn't match the array type. - // TODO(tarcieri): deprecate this before the v0.2 release - // #[deprecated(since = "0.2.0", note = "use TryFrom instead")] - #[inline] - pub fn from_slice(slice: &[T]) -> &Self { - slice.try_into().expect("slice length mismatch") - } - - /// Convert the given mutable slice to a mutable reference to a hybrid array. - /// - /// # Panics - /// - /// Panics if the slice's length doesn't match the array type. - // TODO(tarcieri): deprecate this before the v0.2 release - // #[deprecated(since = "0.2.0", note = "use TryFrom instead")] - #[inline] - pub fn from_mut_slice(slice: &mut [T]) -> &mut Self { - slice.try_into().expect("slice length mismatch") - } - - /// Clone the contents of the slice as a new hybrid array. - /// - /// # Panics - /// - /// Panics if the slice's length doesn't match the array type. - // TODO(tarcieri): deprecate this before the v0.2 release - // #[deprecated(since = "0.2.0", note = "use TryFrom instead")] - #[inline] - pub fn clone_from_slice(slice: &[T]) -> Self - where - Self: Clone, - { - slice.try_into().expect("slice length mismatch") - } - /// Returns an iterator over the array. #[inline] pub fn iter(&self) -> Iter<'_, T> { @@ -351,6 +312,42 @@ where (chunks, tail) } } + + /// Convert the given slice into a reference to a hybrid array. + /// + /// # Panics + /// + /// Panics if the slice's length doesn't match the array type. + #[deprecated(since = "0.2.0", note = "use `TryFrom` instead")] + #[inline] + pub fn from_slice(slice: &[T]) -> &Self { + slice.try_into().expect("slice length mismatch") + } + + /// Convert the given mutable slice to a mutable reference to a hybrid array. + /// + /// # Panics + /// + /// Panics if the slice's length doesn't match the array type. + #[deprecated(since = "0.2.0", note = "use `TryFrom` instead")] + #[inline] + pub fn from_mut_slice(slice: &mut [T]) -> &mut Self { + slice.try_into().expect("slice length mismatch") + } + + /// Clone the contents of the slice as a new hybrid array. + /// + /// # Panics + /// + /// Panics if the slice's length doesn't match the array type. + #[deprecated(since = "0.2.0", note = "use `TryFrom` instead")] + #[inline] + pub fn clone_from_slice(slice: &[T]) -> Self + where + Self: Clone, + { + slice.try_into().expect("slice length mismatch") + } } // Impls which depend on the inner array type being `[T; N]`. diff --git a/tests/mod.rs b/tests/mod.rs index 62fe47d..3ecf313 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -7,12 +7,6 @@ const EXAMPLE_SLICE: &[u8] = &[1, 2, 3, 4, 5, 6]; /// Ensure `ArrayN` works as expected. const _FOO: ArrayN = Array([1, 2, 3, 4]); -#[test] -fn clone_from_slice() { - let array = Array::::clone_from_slice(EXAMPLE_SLICE); - assert_eq!(array.as_slice(), EXAMPLE_SLICE); -} - #[test] fn tryfrom_slice_for_array() { assert!(Array::::try_from(EXAMPLE_SLICE).is_err()); @@ -37,8 +31,8 @@ fn tryfrom_slice_for_array_ref() { #[test] fn concat() { - let prefix = Array::::clone_from_slice(&EXAMPLE_SLICE[..2]); - let suffix = Array::::clone_from_slice(&EXAMPLE_SLICE[2..]); + let prefix = Array::::try_from(&EXAMPLE_SLICE[..2]).unwrap(); + let suffix = Array::::try_from(&EXAMPLE_SLICE[2..]).unwrap(); let array = prefix.concat(suffix); assert_eq!(array.as_slice(), EXAMPLE_SLICE); @@ -46,8 +40,7 @@ fn concat() { #[test] fn split() { - let array = Array::::clone_from_slice(EXAMPLE_SLICE); - + let array = Array::::try_from(EXAMPLE_SLICE).unwrap(); let (prefix, suffix) = array.split::(); assert_eq!(prefix.as_slice(), &EXAMPLE_SLICE[..2]); @@ -56,8 +49,7 @@ fn split() { #[test] fn split_ref() { - let array = Array::::clone_from_slice(EXAMPLE_SLICE); - + let array = Array::::try_from(EXAMPLE_SLICE).unwrap(); let (prefix, suffix) = array.split_ref::(); assert_eq!(prefix.as_slice(), &EXAMPLE_SLICE[..3]); @@ -66,8 +58,7 @@ fn split_ref() { #[test] fn split_ref_mut() { - let array = &mut Array::::clone_from_slice(EXAMPLE_SLICE); - + let array = &mut Array::::try_from(EXAMPLE_SLICE).unwrap(); let (prefix, suffix) = array.split_ref_mut::(); assert_eq!(prefix.as_slice(), &EXAMPLE_SLICE[..4]); @@ -141,8 +132,15 @@ fn maybe_uninit() { } #[test] -fn test_map() { +fn map() { let base = Array::::from([1, 2, 3, 4]); let expected = Array::::from([2, 3, 4, 5]); assert_eq!(base.map(|item| (item as u16) + 1), expected); } + +#[test] +#[allow(deprecated)] +fn clone_from_slice() { + let array = Array::::clone_from_slice(EXAMPLE_SLICE); + assert_eq!(array.as_slice(), EXAMPLE_SLICE); +}