Skip to content

Commit

Permalink
hybrid-array: get rid of ArrayExt::from_slice (#1008)
Browse files Browse the repository at this point in the history
It can be composed in terms of other features.
  • Loading branch information
tarcieri committed Dec 30, 2023
1 parent 52dd5b1 commit db9c862
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ where
}

/// Create array from a slice.
// TODO(tarcieri): deprecate this before the v0.2 release
// #[deprecated(since = "0.2.0", note = "use TryFrom instead")]
pub fn from_slice(slice: &[T]) -> Result<Self, TryFromSliceError>
where
T: Copy,
{
ArrayExt::from_slice(slice).map(Self)
slice.try_into()
}

/// Returns an iterator over the array.
Expand Down Expand Up @@ -482,7 +484,8 @@ where

#[inline]
fn try_from(slice: &'a [T]) -> Result<Array<T, U>, TryFromSliceError> {
ArrayExt::from_slice(slice).map(Self)
check_slice_length::<T, U>(slice)?;
Ok(Self::from_fn(|n| slice[n]))
}
}

Expand Down Expand Up @@ -606,12 +609,6 @@ pub trait ArrayExt<T>: Sized {
fn from_fn<F>(cb: F) -> Self
where
F: FnMut(usize) -> T;

/// Create array from a slice, returning [`TryFromSliceError`] if the slice
/// length does not match the array length.
fn from_slice(slice: &[T]) -> Result<Self, TryFromSliceError>
where
T: Copy;
}

impl<T, const N: usize> ArrayExt<T> for [T; N] {
Expand All @@ -627,13 +624,6 @@ impl<T, const N: usize> ArrayExt<T> for [T; N] {
res
})
}

fn from_slice(slice: &[T]) -> Result<Self, TryFromSliceError>
where
T: Copy,
{
slice.try_into()
}
}

/// Trait which associates a [`usize`] size and `ArrayType` with a
Expand Down

0 comments on commit db9c862

Please sign in to comment.