File: vec_try.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 (17 lines) | stat: -rw-r--r-- 621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#![feature(try_reserve)]

use static_alloc::Bump;

// Provide more memory than #[test] needs for the setup.
// Previously this constant was 1 << 16 which proved too little. This does not cost much more than
// some compile time. Not much, actually. Except on wasm where it will produce a zeroed data
// segment that can be quite large.
const MORE_THAN_CFG_TEST_ALLOCATES: usize = 1 << 20;
#[global_allocator]
static A: Bump<[u8; MORE_THAN_CFG_TEST_ALLOCATES]> = Bump::uninit();

#[test]
fn vec_fail_reserve() {
    let mut v: Vec<u8> = Vec::new();
    assert!(v.try_reserve(MORE_THAN_CFG_TEST_ALLOCATES + 1).is_err());
}