Skip to content

Commit 5d38a11

Browse files
authored
Merge pull request #134 from threema-danilo/docs-clarify-panic
Docs: Make panicking behavior on from_slice more obvious
2 parents 1f50abb + d0b5e83 commit 5d38a11

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/lib.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,19 @@ where
549549

550550
/// Converts slice to a generic array reference with inferred length;
551551
///
552-
/// Length of the slice must be equal to the length of the array.
552+
/// # Panics
553+
///
554+
/// Panics if the slice is not equal to the length of the array.
553555
#[inline]
554556
pub fn from_slice(slice: &[T]) -> &GenericArray<T, N> {
555557
slice.into()
556558
}
557559

558560
/// Converts mutable slice to a mutable generic array reference
559561
///
560-
/// Length of the slice must be equal to the length of the array.
562+
/// # Panics
563+
///
564+
/// Panics if the slice is not equal to the length of the array.
561565
#[inline]
562566
pub fn from_mut_slice(slice: &mut [T]) -> &mut GenericArray<T, N> {
563567
slice.into()
@@ -567,7 +571,9 @@ where
567571
impl<'a, T, N: ArrayLength<T>> From<&'a [T]> for &'a GenericArray<T, N> {
568572
/// Converts slice to a generic array reference with inferred length;
569573
///
570-
/// Length of the slice must be equal to the length of the array.
574+
/// # Panics
575+
///
576+
/// Panics if the slice is not equal to the length of the array.
571577
#[inline]
572578
fn from(slice: &[T]) -> &GenericArray<T, N> {
573579
assert_eq!(slice.len(), N::USIZE);
@@ -579,7 +585,9 @@ impl<'a, T, N: ArrayLength<T>> From<&'a [T]> for &'a GenericArray<T, N> {
579585
impl<'a, T, N: ArrayLength<T>> From<&'a mut [T]> for &'a mut GenericArray<T, N> {
580586
/// Converts mutable slice to a mutable generic array reference
581587
///
582-
/// Length of the slice must be equal to the length of the array.
588+
/// # Panics
589+
///
590+
/// Panics if the slice is not equal to the length of the array.
583591
#[inline]
584592
fn from(slice: &mut [T]) -> &mut GenericArray<T, N> {
585593
assert_eq!(slice.len(), N::USIZE);
@@ -594,7 +602,9 @@ where
594602
{
595603
/// Construct a `GenericArray` from a slice by cloning its content
596604
///
597-
/// Length of the slice must be equal to the length of the array
605+
/// # Panics
606+
///
607+
/// Panics if the slice is not equal to the length of the array.
598608
#[inline]
599609
pub fn clone_from_slice(list: &[T]) -> GenericArray<T, N> {
600610
Self::from_exact_iter(list.iter().cloned())

0 commit comments

Comments
 (0)