diff --git a/Cargo.toml b/Cargo.toml index fadaecb..48236c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ edition = "2021" name = "elf" [dependencies] -hashbrown = { version = "0.14.0", optional = true } +hashbrown = { version = "0.14.0", optional = true, default-features = false } [features] default = ["std", "to_str"] diff --git a/src/elf_stream.rs b/src/elf_stream.rs index 09c1039..47c20e0 100644 --- a/src/elf_stream.rs +++ b/src/elf_stream.rs @@ -1,9 +1,9 @@ use core::ops::Range; #[cfg(not(feature = "std"))] -use hashbrown::HashMap; +use alloc::{boxed::Box, collections::BTreeMap as BufferMap, vec, vec::Vec}; #[cfg(feature = "std")] -use std::collections::HashMap; +use std::collections::BTreeMap as BufferMap; use crate::abi; use crate::compression::CompressionHeader; @@ -683,7 +683,7 @@ impl ElfStream { struct CachingReader { reader: R, stream_len: u64, - bufs: HashMap<(usize, usize), Box<[u8]>>, + bufs: BufferMap<(usize, usize), Box<[u8]>>, } impl CachingReader { @@ -694,7 +694,7 @@ impl CachingReader { Ok(CachingReader { reader, stream_len, - bufs: HashMap::<(usize, usize), Box<[u8]>>::default(), + bufs: BufferMap::<(usize, usize), Box<[u8]>>::default(), }) } diff --git a/src/io_traits.rs b/src/io_traits.rs index 15cf143..534be84 100644 --- a/src/io_traits.rs +++ b/src/io_traits.rs @@ -1,6 +1,8 @@ #[cfg(feature = "std")] pub type StreamError = std::io::Error; + #[cfg(not(feature = "std"))] +#[derive(Debug)] pub struct StreamError { pub message: &'static str, } diff --git a/src/lib.rs b/src/lib.rs index 88cf1e3..430d04a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,6 +130,9 @@ #![warn(rust_2018_idioms)] #![deny(missing_debug_implementations)] +#[cfg(not(feature = "std"))] +extern crate alloc; + pub mod abi; pub mod compression;