Method in prelude · Vec auto-imported

Vec::push

pub fn push(T x)
Source: compiler/src/builtin_docs/prelude.hy

Appends x to the end of the vector.

Called on a Vec value as value.push(…).

Parameters#

NameType
xT

Examples#

use tests::assert;
let v: Vec<int> = Vec::new();
v.push(5);
assert!(v[0] == 5);

See also#

  • Vec: A growable, heap-allocated vector of T values.
  • Vec::new: Creates a new, empty vector.
  • Vec::with_capacity: Creates an empty vector with room for at least n elements.
  • Vec::from: Creates a vector holding a copy of the elements of the fixed array arr.
  • Vec::pop: Removes the last element and returns it, or None when the vector is empty.
  • Vec::insert: Inserts x at index i, shifting later elements one place to the right.
  • Vec::remove: Removes the element at index i and returns it, shifting later elements left.
  • Vec::clear: Removes every element.
↑ ↓ navigate ↵ open