You cannot use the alloc crate without std because alloc depends on std for its implementation in standard Rust builds. To use alloc in a no_std environment, you must enable the alloc feature in your Cargo.toml and ensure your crate is compiled with #![no_std] while providing a custom allocator if needed, but typically alloc is used alongside std or in embedded contexts with specific configurations. For a true no_std setup with alloc, add #![no_std] and #![no_main] to your entry point, then use extern crate alloc; and configure your Cargo.toml with default-features = false for dependencies that might pull in std.
#![no_std]
#![no_main]
extern crate alloc;
use alloc::vec::Vec;
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn _start() -> ! {
let _v: Vec<u8> = Vec::new();
loop {}
}
Note: This requires a custom panic handler and a linker script for embedded targets; alloc alone does not provide a full runtime without std or an embedded environment.