diff --git a/src/from_fn.rs b/src/from_fn.rs index 0034eb5..b10f87d 100644 --- a/src/from_fn.rs +++ b/src/from_fn.rs @@ -13,11 +13,8 @@ where { /// Create array where each array element `T` is returned by the `f` call. #[inline] - pub fn from_fn(mut f: F) -> Self - where - F: FnMut(usize) -> T, - { - Self::try_from_fn::(|n| Ok(f(n))).expect("should never fail") + pub fn from_fn(mut f: impl FnMut(usize) -> T) -> Self { + Self::try_from_fn::(|n| Ok(f(n))).expect("should never fail") } /// Create array fallibly where each array element `T` is returned by the `f` call, or return @@ -26,10 +23,7 @@ where /// # Errors /// /// Propagates the `E` type returned from the provided `F` in the event of error. - pub fn try_from_fn(f: F) -> Result - where - F: FnMut(usize) -> Result, - { + pub fn try_from_fn(f: impl FnMut(usize) -> Result) -> Result { let mut array = Array::, U>::uninit(); try_from_fn_erased(array.0.as_mut(), f)?; diff --git a/tests/mod.rs b/tests/mod.rs index 68f6255..68aaffd 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -82,10 +82,10 @@ fn from_fn() { #[test] fn try_from_fn() { - let array = Array::::try_from_fn::<(), _>(|n| Ok((n + 1) as u8)).unwrap(); + let array = Array::::try_from_fn::<()>(|n| Ok((n + 1) as u8)).unwrap(); assert_eq!(array.as_slice(), EXAMPLE_SLICE); - let err = Array::::try_from_fn::<&'static str, _>(|_| Err("err")) + let err = Array::::try_from_fn::<&'static str>(|_| Err("err")) .err() .unwrap();