How to use vec! macro in a #![no_std] library?

In addition to Tims answer, if you have an embedded system and you have an allocator, but not std, you can use

#[macro_use]
extern crate alloc;

to be able to use vec!


vec! is a macro so you have to add #[macro_use]:

#[cfg(test)]
#[macro_use]
extern crate std;

If you are on a nightly compiler, you can also use the use_extern_macros feature:

#![feature(use_extern_macros)]

#[cfg(test)]
extern crate std;

#[cfg(test)]
mod test {
    use std::vec;
}

Tags:

Rust