method List.insert
Inserts x before the element at index i; later elements move one place up. i == len() appends.
Example:
fn main() io {
var xs = [1, 2, 4]
xs.insert(2, 3)
print("{xs}")
}Вывод
[1, 2, 3, 4]
Inserts x before index i; later elements move up.
Example:
fn main() io {
var xs = [1, 3]
xs.insert(1, 2)
print("{xs}")
}Вывод
[1, 2, 3]
pub(api) var fn insert(i: usize, x: T)Сложность. O(n) in the number of elements after `i`.
С версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
i | usize |
x | T |
Ошибки
panics when `i > len()`.
Эффекты
не объявлены (чистая, пока тело не говорит иное)
Определено в: std/core/collections.oxl:211