Method in prelude · Range auto-imported

Range::to_vec

pub fn to_vec() -> Vec<T>
Source: compiler/src/builtin_docs/prelude.hy

Collects the range into a new Vec<T>.

Only numeric ranges (int, byte, float) can be collected; other element types are a compile-time error.

Called on a Range value as value.to_vec(…).

Returns#

Vec<T>

Examples#

use tests::assert;
let v = (2..5).to_vec();
assert!(v.len() == 3);
assert!(v[0] == 2);
assert!((5..2).to_vec().len() == 0);

See also#

  • Vec
  • int
  • byte
  • float
  • Range: A lazy half-open range start..end: every value from start up to, but not including, end.
↑ ↓ navigate ↵ open