to_array

Mojo function 🡭

to_array

fn def to_array[size: Int, T: Copyable & Deinitable, o: Origin[mut=o.mut]](data: Span[T, o]) -> Array[T, size]

Copy a size-length span into a fixed-size Array.

Checks len(data) == size and raises otherwise.

Parameters:

  • size (Int): The expected length of data and of the resulting array.
  • T (Copyable & Deinitable): The element type.
  • o (Origin[mut=mut]): The origin of the span.

Args:

  • data (Span[T, o]): The span to copy from.

Returns:

Array[T, size]: An Array[T, size] holding a copy of data.

Raises:

Error: If len(data) != size.