Returns an array of the same size as self, with function f applied to each element\nin order.
If you don’t necessarily need a new fixed-size array, consider using\nIterator::map instead.
Note that this method is eager. It evaluates f all N times before\nreturning the new array.
That means that arr.map(f).map(g) is, in general, not equivalent to\narray.map(|x| g(f(x))), as the former calls f 4 times then g 4 times,\nwhereas the latter interleaves the calls (fgfgfgfg).
A consequence of this is that it can have fairly-high stack usage, especially\nin debug mode or for long arrays. The backend may be able to optimize it\naway, but especially for complicated mappings it might not be able to.
\nIf you’re doing a one-step map and really want an array as the result,\nthen absolutely use this method. Its implementation uses a bunch of tricks\nto help the optimizer handle it well. Particularly for simple arrays,\nlike [u8; 3] or [f32; 4], there’s nothing to be concerned about.
However, if you don’t actually need an array of the results specifically,\njust to process them, then you likely want Iterator::map instead.
For example, rather than doing an array-to-array map of all the elements\nin the array up-front and only iterating after that completes,
\n\nfor x in my_array.map(f) {\n // ...\n}It’s often better to use an iterator along the lines of
\n\nfor x in my_array.into_iter().map(f) {\n // ...\n}as that’s more likely to avoid large temporaries.
\nlet x = [1, 2, 3];\nlet y = x.map(|v| v + 1);\nassert_eq!(y, [2, 3, 4]);\n\nlet x = [1, 2, 3];\nlet mut temp = 0;\nlet y = x.map(|v| { temp += 1; v * temp });\nassert_eq!(y, [1, 4, 9]);\n\nlet x = [\"Ferris\", \"Bueller's\", \"Day\", \"Off\"];\nlet y = x.map(|v| v.len());\nassert_eq!(y, [6, 9, 3, 3]);array_try_map)A fallible function f applied to each element on array self in order to\nreturn an array the same size as self or the first error encountered.
The return type of this function depends on the return type of the closure.\nIf you return Result<T, E> from the closure, you’ll get a Result<[T; N], E>.\nIf you return Option<T> from the closure, you’ll get an Option<[T; N]>.
#![feature(array_try_map)]\n\nlet a = [\"1\", \"2\", \"3\"];\nlet b = a.try_map(|v| v.parse::<u32>()).unwrap().map(|v| v + 1);\nassert_eq!(b, [2, 3, 4]);\n\nlet a = [\"1\", \"2a\", \"3\"];\nlet b = a.try_map(|v| v.parse::<u32>());\nassert!(b.is_err());\n\nuse std::num::NonZero;\n\nlet z = [1, 2, 0, 3, 4];\nassert_eq!(z.try_map(NonZero::new), None);\n\nlet a = [1, 2, 3];\nlet b = a.try_map(NonZero::new);\nlet c = b.map(|x| x.map(NonZero::get));\nassert_eq!(c, Some(a));Returns a slice containing the entire array. Equivalent to &s[..].
Returns a mutable slice containing the entire array. Equivalent to\n&mut s[..].
Borrows each element and returns an array of references with the same\nsize as self.
let floats = [3.1, 2.7, -1.0];\nlet float_refs: [&f64; 3] = floats.each_ref();\nassert_eq!(float_refs, [&3.1, &2.7, &-1.0]);This method is particularly useful if combined with other methods, like\nmap. This way, you can avoid moving the original\narray if its elements are not Copy.
let strings = [\"Ferris\".to_string(), \"♥\".to_string(), \"Rust\".to_string()];\nlet is_ascii = strings.each_ref().map(|s| s.is_ascii());\nassert_eq!(is_ascii, [true, false, true]);\n\n// We can still access the original array: it has not been moved.\nassert_eq!(strings.len(), 3);Borrows each element mutably and returns an array of mutable references\nwith the same size as self.
\nlet mut floats = [3.1, 2.7, -1.0];\nlet float_refs: [&mut f64; 3] = floats.each_mut();\n*float_refs[0] = 0.0;\nassert_eq!(float_refs, [&mut 0.0, &mut 2.7, &mut -1.0]);\nassert_eq!(floats, [0.0, 2.7, -1.0]);split_array)Divides one array reference into two at an index.
\nThe first will contain all indices from [0, M) (excluding\nthe index M itself) and the second will contain all\nindices from [M, N) (excluding the index N itself).
Panics if M > N.
#![feature(split_array)]\n\nlet v = [1, 2, 3, 4, 5, 6];\n\n{\n let (left, right) = v.split_array_ref::<0>();\n assert_eq!(left, &[]);\n assert_eq!(right, &[1, 2, 3, 4, 5, 6]);\n}\n\n{\n let (left, right) = v.split_array_ref::<2>();\n assert_eq!(left, &[1, 2]);\n assert_eq!(right, &[3, 4, 5, 6]);\n}\n\n{\n let (left, right) = v.split_array_ref::<6>();\n assert_eq!(left, &[1, 2, 3, 4, 5, 6]);\n assert_eq!(right, &[]);\n}split_array)Divides one mutable array reference into two at an index.
\nThe first will contain all indices from [0, M) (excluding\nthe index M itself) and the second will contain all\nindices from [M, N) (excluding the index N itself).
Panics if M > N.
#![feature(split_array)]\n\nlet mut v = [1, 0, 3, 0, 5, 6];\nlet (left, right) = v.split_array_mut::<2>();\nassert_eq!(left, &mut [1, 0][..]);\nassert_eq!(right, &mut [3, 0, 5, 6]);\nleft[1] = 2;\nright[1] = 4;\nassert_eq!(v, [1, 2, 3, 4, 5, 6]);split_array)Divides one array reference into two at an index from the end.
\nThe first will contain all indices from [0, N - M) (excluding\nthe index N - M itself) and the second will contain all\nindices from [N - M, N) (excluding the index N itself).
Panics if M > N.
#![feature(split_array)]\n\nlet v = [1, 2, 3, 4, 5, 6];\n\n{\n let (left, right) = v.rsplit_array_ref::<0>();\n assert_eq!(left, &[1, 2, 3, 4, 5, 6]);\n assert_eq!(right, &[]);\n}\n\n{\n let (left, right) = v.rsplit_array_ref::<2>();\n assert_eq!(left, &[1, 2, 3, 4]);\n assert_eq!(right, &[5, 6]);\n}\n\n{\n let (left, right) = v.rsplit_array_ref::<6>();\n assert_eq!(left, &[]);\n assert_eq!(right, &[1, 2, 3, 4, 5, 6]);\n}split_array)Divides one mutable array reference into two at an index from the end.
\nThe first will contain all indices from [0, N - M) (excluding\nthe index N - M itself) and the second will contain all\nindices from [N - M, N) (excluding the index N itself).
Panics if M > N.
#![feature(split_array)]\n\nlet mut v = [1, 0, 3, 0, 5, 6];\nlet (left, right) = v.rsplit_array_mut::<4>();\nassert_eq!(left, &mut [1, 0]);\nassert_eq!(right, &mut [3, 0, 5, 6][..]);\nleft[1] = 2;\nright[1] = 4;\nassert_eq!(v, [1, 2, 3, 4, 5, 6]);const_generics only.fmt::Debug when an assert fails. Read morefmt::Debug when an assert fails. Read moreabs comparison, displayed when an assert fails.ulps comparison, displayed when an assert fails.fmt::Debug. Read moreabs_all comparison, displayed when an assert fails.ulps_all comparison, displayed when an assert fails.tarpaulin_include only.Note that overly-large arrays may cause the conversions to fail.
\nself in a BitArray.Reader].self into buf in the expected format for the database.self is equal to other, using a relative tolerance\ncomparison, scaled to the granularity of the input with the largest\nmagnitude. Read moreself is equal to other, using a relative tolerance\ncomparison, scaled to the granularity of the input with the smallest\nmagnitude. Read moreself is equal to other, using a relative tolerance\ncomparison, scaled to the granularity of the first input. Read moreself is equal to other, using a relative tolerance\ncomparison, scaled to the granularity of the second input. Read moreSelf, with fields recursively wrapped\nby DebugUlpsDiff.relaxed_coherence only.&Self. Read morearray-impls only.Type in its binary format. Read moreType.tracker. Read moretracker. Read moreThe hash of an array is the same as that of the corresponding slice,\nas required by the Borrow implementation.
use std::hash::BuildHasher;\n\nlet b = std::hash::RandomState::new();\nlet a: [u8; 3] = [0xa8, 0x3c, 0x09];\nlet s: &[u8] = &[0xa8, 0x3c, 0x09];\nassert_eq!(b.hash_one(a), b.hash_one(s));Creates a consuming iterator, that is, one that moves each value out of\nthe array (from start to end).
\nThe array cannot be used after calling this unless T implements\nCopy, so the whole array is copied.
Arrays have special behavior when calling .into_iter() prior to the\n2021 edition – see the array Editions section for more information.
Self. Read moreVarULE] type for this data struct, or [()]\nif it cannot be represented as [VarULE].Implements comparison of arrays lexicographically.
\n","flow::engine::TableName"],[" Implements comparison of arrays lexicographically. Tries to create an array Tries to create an array Gets the entire contents of the If the length doesn’t match, the input comes back in If you’re fine with just getting a prefix of the Gets the entire contents of the If the length doesn’t match, the input comes back in If you’re fine with just getting a prefix of the Impl [ Impl [impl<T, U, const N: usize> PartialEq<&[U]> for [T; N]
impl<T, U, const N: usize> PartialEq<&mut [U]> for [T; N]
impl<T, U, const N: usize> PartialEq<[U]> for [T; N]
impl<T, U, const N: usize> PartialEq<[U; N]> for [T; N]
impl<T, const N: usize> PartialOrd for [T; N]
impl<S, const N: usize> Point for [S; N]
const DIMENSIONS: usize = N
fn generate(generator: impl FnMut(usize) -> S) -> [S; N]
impl<T> Serialize for [T; 3]
fn serialize<S>(\n &self,\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
impl<T, As, const N: usize> SerializeAs<[T; N]> for [As; N]
fn serialize_as<S>(\n array: &[T; N],\n serializer: S,\n) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
impl<T, const N: usize> SlicePattern for [T; N]
impl<T, const N: usize> ToSql for [T; N]
array-impls only.fn to_sql(\n &self,\n ty: &Type,\n w: &mut BytesMut,\n) -> Result<IsNull, Box<dyn Error + Send + Sync>>
self into the binary format of the specified\nPostgres Type, appending it to out. Read morefn accepts(ty: &Type) -> bool
Type.fn to_sql_checked(\n &self,\n ty: &Type,\n out: &mut BytesMut,\n) -> Result<IsNull, Box<dyn Error + Send + Sync>>
fn encode_format(&self, _ty: &Type) -> Format
impl<T, const N: usize> TryFrom<&[T]> for [T; N]
[T; N] by copying from a slice &[T].\nSucceeds if slice.len() == N.let bytes: [u8; 3] = [1, 0, 2];\n\nlet bytes_head: [u8; 2] = <[u8; 2]>::try_from(&bytes[0..2]).unwrap();\nassert_eq!(1, u16::from_le_bytes(bytes_head));\n\nlet bytes_tail: [u8; 2] = bytes[1..3].try_into().unwrap();\nassert_eq!(512, u16::from_le_bytes(bytes_tail));impl<T, const N: usize> TryFrom<&mut [T]> for [T; N]
[T; N] by copying from a mutable slice &mut [T].\nSucceeds if slice.len() == N.let mut bytes: [u8; 3] = [1, 0, 2];\n\nlet bytes_head: [u8; 2] = <[u8; 2]>::try_from(&mut bytes[0..2]).unwrap();\nassert_eq!(1, u16::from_le_bytes(bytes_head));\n\nlet bytes_tail: [u8; 2] = (&mut bytes[1..3]).try_into().unwrap();\nassert_eq!(512, u16::from_le_bytes(bytes_tail));impl<T, A, const N: usize> TryFrom<Vec<T, A>> for [T; N]
fn try_from(vec: Vec<T, A>) -> Result<[T; N], Vec<T, A>>
Vec<T> as an array,\nif its size exactly matches that of the requested array.§Examples
\nassert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3]));\nassert_eq!(<Vec<i32>>::new().try_into(), Ok([]));Err:let r: Result<[i32; 4], _> = (0..10).collect::<Vec<_>>().try_into();\nassert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));Vec<T>,\nyou can call .truncate(N) first.let mut v = String::from(\"hello world\").into_bytes();\nv.sort();\nv.truncate(2);\nlet [a, b]: [_; 2] = v.try_into().unwrap();\nassert_eq!(a, b' ');\nassert_eq!(b, b'd');impl<T, A, const N: usize> TryFrom<Vec<T, A>> for [T; N]
fn try_from(vec: Vec<T, A>) -> Result<[T; N], Vec<T, A>>
Vec<T> as an array,\nif its size exactly matches that of the requested array.§Examples
\nassert_eq!(vec![1, 2, 3].try_into(), Ok([1, 2, 3]));\nassert_eq!(<Vec<i32>>::new().try_into(), Ok([]));Err:let r: Result<[i32; 4], _> = (0..10).collect::<Vec<_>>().try_into();\nassert_eq!(r, Err(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]));Vec<T>,\nyou can call .truncate(N) first.let mut v = String::from(\"hello world\").into_bytes();\nv.sort();\nv.truncate(2);\nlet [a, b]: [_; 2] = v.try_into().unwrap();\nassert_eq!(a, b' ');\nassert_eq!(b, b'd');impl<T, const N: usize> TryFromBytes for [T; N]
fn try_ref_from_bytes(\n source: &[u8],\n) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_prefix(\n source: &[u8],\n) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_suffix(\n source: &[u8],\n) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_mut_from_bytes(\n bytes: &mut [u8],\n) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
fn try_mut_from_prefix(\n source: &mut [u8],\n) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
fn try_mut_from_suffix(\n source: &mut [u8],\n) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
fn try_ref_from_bytes_with_elems(\n source: &[u8],\n count: usize,\n) -> Result<&Self, ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_ref_from_prefix_with_elems(\n source: &[u8],\n count: usize,\n) -> Result<(&Self, &[u8]), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
source as a &Self with\na DST length equal to count. Read morefn try_ref_from_suffix_with_elems(\n source: &[u8],\n count: usize,\n) -> Result<(&[u8], &Self), ConvertError<AlignmentError<&[u8], Self>, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
source as a &Self with\na DST length equal to count. Read morefn try_mut_from_bytes_with_elems(\n source: &mut [u8],\n count: usize,\n) -> Result<&mut Self, ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
fn try_mut_from_prefix_with_elems(\n source: &mut [u8],\n count: usize,\n) -> Result<(&mut Self, &mut [u8]), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
source as a &mut Self\nwith a DST length equal to count. Read morefn try_mut_from_suffix_with_elems(\n source: &mut [u8],\n count: usize,\n) -> Result<(&mut [u8], &mut Self), ConvertError<AlignmentError<&mut [u8], Self>, SizeError<&mut [u8], Self>, ValidityError<&mut [u8], Self>>>
source as a &mut Self\nwith a DST length equal to count. Read morefn try_read_from_bytes(\n source: &[u8],\n) -> Result<Self, ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_read_from_prefix(\n source: &[u8],\n) -> Result<(Self, &[u8]), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
fn try_read_from_suffix(\n source: &[u8],\n) -> Result<(&[u8], Self), ConvertError<Infallible, SizeError<&[u8], Self>, ValidityError<&[u8], Self>>>
impl<T, const N: usize> ULE for [T; N]
fn parse_bytes_to_slice(bytes: &[u8]) -> Result<&[Self], UleError>
unsafe fn slice_from_bytes_unchecked(bytes: &[u8]) -> &[Self]
&[u8], and return it as &[Self] with the same lifetime, assuming\nthat this byte slice has previously been run through [Self::parse_bytes_to_slice()] with\nsuccess. Read morefn slice_as_bytes(slice: &[Self]) -> &[u8] ⓘ
impl<T, const N: usize> UnsizedCopy for [T; N]
fn ptr_with_addr(&self, addr: *const ()) -> *const [T; N]
Self. Read morefn unsized_copy_into<T>(&self) -> T
self into a new container. Read moreimpl<'a, T, const N: usize> Yokeable<'a> for [T; N]
type Output = [<T as Yokeable<'a>>::Output; N]
Self with the 'static replaced with 'a, i.e. Self<'a>fn transform_owned(self) -> <[T; N] as Yokeable<'a>>::Output
unsafe fn make(from: <[T; N] as Yokeable<'a>>::Output) -> [T; N]
Self<'a>’s lifetime. Read morefn transform_mut<F>(&'a mut self, f: F)
self between &'a mut Self<'static> and &'a mut Self<'a>,\nand pass it to f. Read moreimpl<'a, T, const N: usize> ZeroMapKV<'a> for [T; N]
impl<Z, const N: usize> Zeroize for [Z; N]
Zeroize] on arrays of types that impl [Zeroize].impl<T, const N: usize> CloneFromCell for [T; N]
impl<T, const N: usize> ConstParamTy_ for [T; N]
impl<T, const N: usize> Copy for [T; N]
impl<T, const N: usize> Eq for [T; N]
impl<T, const N: usize> EqULE for [T; N]
impl<T, const N: usize> Immutable for [T; N]
impl<T> Pod for [T; 3]
impl<const N: usize, T> Pod for [T; N]
impl<T, const N: usize> StructuralPartialEq for [T; N]
impl<T, const N: usize> Unaligned for [T; N]
impl<Z, const N: usize> ZeroizeOnDrop for [Z; N]
ZeroizeOnDrop] on arrays of types that impl [ZeroizeOnDrop].