File: vec.rs

package info (click to toggle)
rust-static-alloc 0.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 284 kB
  • sloc: makefile: 4
file content (30 lines) | stat: -rw-r--r-- 630 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use static_alloc::Bump;

#[global_allocator]
static A: Bump<[u8; 1 << 20]> = Bump::uninit();

#[test]
fn ok_vec() {
    let v = vec![0xdeadbeef_u32; 128];
    println!("{:x?}", v);
    v.into_iter()
        .for_each(|x| assert_eq!(x, 0xdeadbeef_u32));
}

#[test]
fn shrink() {
    let mut v = vec![0xdeadbeef_u32; 2];
    v.pop();
    v.shrink_to_fit();
    assert_eq!(v.capacity(), 1);
    assert_eq!(&v, &[0xdeadbeef_u32; 1]);
}

#[test]
fn grow() {
    let mut v = vec![0xdeadbeef_u32; 2];
    assert_eq!(v.capacity(), 2);
    v.push(0xdeadbeef_u32);
    assert!(v.capacity() > 3);
    assert_eq!(&v, &[0xdeadbeef_u32; 3]);
}