mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
core: Add vec::unshift
This commit is contained in:
parent
397f33fd35
commit
e4af1ca065
@ -323,6 +323,11 @@ fn shift<T: copy>(&v: [const T]) -> T {
|
||||
ret e;
|
||||
}
|
||||
|
||||
#[doc = "Prepend an element to a vector"]
|
||||
fn unshift<T: copy>(&v: [const T], +t: T) {
|
||||
v = [const t] + v;
|
||||
}
|
||||
|
||||
#[doc = "Remove the last element from a vector and return it"]
|
||||
fn pop<T>(&v: [const T]) -> T unsafe {
|
||||
let ln = len(v);
|
||||
@ -1734,6 +1739,13 @@ mod tests {
|
||||
let addr_imm = unsafe::to_ptr(x_imm);
|
||||
assert addr == addr_imm;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unshift() {
|
||||
let x = [1, 2, 3];
|
||||
unshift(x, 0);
|
||||
assert x == [0, 1, 2, 3];
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
Loading…
Reference in New Issue
Block a user