Skip to content

Commit 483f641

Browse files
Simplify [T; N]::try_map signature
People keep making fun of this signature for being so gnarly. Associated type bounds lend it a much simpler scribbling. ChangeOutputType can also come along for the ride.
1 parent c8170e6 commit 483f641

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

core/src/array/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,9 @@ impl<T, const N: usize> [T; N] {
533533
/// assert_eq!(c, Some(a));
534534
/// ```
535535
#[unstable(feature = "array_try_map", issue = "79711")]
536-
pub fn try_map<F, R>(self, f: F) -> ChangeOutputType<R, [R::Output; N]>
536+
pub fn try_map<R>(self, f: impl FnMut(T) -> R) -> ChangeOutputType<R, [R::Output; N]>
537537
where
538-
F: FnMut(T) -> R,
539-
R: Try,
540-
R::Residual: Residual<[R::Output; N]>,
538+
R: Try<Residual: Residual<[R::Output; N]>>,
541539
{
542540
drain_array_with(self, |iter| try_from_trusted_iterator(iter.map(f)))
543541
}

core/src/ops/try_trait.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ pub trait Residual<O> {
363363
}
364364

365365
#[unstable(feature = "pub_crate_should_not_need_unstable_attr", issue = "none")]
366-
pub(crate) type ChangeOutputType<T, V> = <<T as Try>::Residual as Residual<V>>::TryType;
366+
#[allow(type_alias_bounds)]
367+
pub(crate) type ChangeOutputType<T: Try<Residual: Residual<V>>, V> =
368+
<T::Residual as Residual<V>>::TryType;
367369

368370
/// An adapter for implementing non-try methods via the `Try` implementation.
369371
///

0 commit comments

Comments
 (0)