     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57

    //! Implementation for `arr!` macro.

    use super::ArrayLength;
    use core::ops::Add;
    use typenum::U1;

    /// Helper trait for `arr!` macro
    pub trait AddLength<T, N: ArrayLength<T>>: ArrayLength<T> {
        /// Resulting length
        type Output: ArrayLength<T>;
    }

    impl<T, N1, N2> AddLength<T, N2> for N1
    where
        N1: ArrayLength<T> + Add<N2>,
        N2: ArrayLength<T>,
        <N1 as Add<N2>>::Output: ArrayLength<T>,
    {
        type Output = <N1 as Add<N2>>::Output;
    }

    /// Helper type for `arr!` macro
    pub type Inc<T, U> = <U as AddLength<T, U1>>::Output;

    #[doc(hidden)]
    #[macro_export]
    macro_rules! arr_impl {
        ($T:ty; $N:ty, [$($x:expr),*], []) => ({
            unsafe { $crate::transmute::<_, $crate::GenericArray<$T, $N>>([$($x),*]) }
        });
        ($T:ty; $N:ty, [], [$x1:expr]) => (
            arr_impl!($T; $crate::arr::Inc<$T, $N>, [$x1 as $T], [])
        );
        ($T:ty; $N:ty, [], [$x1:expr, $($x:expr),+]) => (
            arr_impl!($T; $crate::arr::Inc<$T, $N>, [$x1 as $T], [$($x),+])
        );
        ($T:ty; $N:ty, [$($y:expr),+], [$x1:expr]) => (
            arr_impl!($T; $crate::arr::Inc<$T, $N>, [$($y),+, $x1 as $T], [])
        );
        ($T:ty; $N:ty, [$($y:expr),+], [$x1:expr, $($x:expr),+]) => (
            arr_impl!($T; $crate::arr::Inc<$T, $N>, [$($y),+, $x1 as $T], [$($x),+])
        );
    }

    /// Macro allowing for easy generation of Generic Arrays.
    /// Example: `let test = arr![u32; 1, 2, 3];`
    #[macro_export]
    macro_rules! arr {
        ($T:ty; $(,)*) => ({
            unsafe { $crate::transmute::<[$T; 0], $crate::GenericArray<$T, $crate::typenum::U0>>([]) }
        });
        ($T:ty; $($x:expr),* $(,)*) => (
            arr_impl!($T; $crate::typenum::U0, [], [$($x),*])
        );
        ($($x:expr,)+) => (arr![$($x),*]);
        () => ("""Macro requires a type, e.g. `let array = arr![u32; 1, 2, 3];`")
    }

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)