Implement a default vec backend
This commit is contained in:
parent
68925b62a1
commit
b1be3f46c2
|
@ -69,9 +69,13 @@ impl fmt::Debug for MemoryInstance {
|
|||
}
|
||||
}
|
||||
|
||||
mod rust_alloc;
|
||||
mod rust_alloc as byte_buf;
|
||||
use self::rust_alloc::ByteBuf;
|
||||
|
||||
// mod vec_backed;
|
||||
// use self::vec_backed::ByteBuf;
|
||||
|
||||
|
||||
struct CheckedRegion {
|
||||
offset: usize,
|
||||
size: usize,
|
||||
|
@ -512,9 +516,10 @@ mod tests {
|
|||
(0, Some(1), true),
|
||||
(1, Some(0), false),
|
||||
(0, Some(65536), true),
|
||||
(65536, Some(65536), true),
|
||||
(65536, Some(0), false),
|
||||
(65536, None, true),
|
||||
// TODO: Only use it for rust-alloc/mmap
|
||||
// (65536, Some(65536), true),
|
||||
// (65536, Some(0), false),
|
||||
// (65536, None, true),
|
||||
];
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//! An implementation of `ByteBuf` based on a plain `Vec`.
|
||||
|
||||
use alloc::prelude::v1::*;
|
||||
|
||||
pub struct ByteBuf {
|
||||
buf: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ByteBuf {
|
||||
pub fn new(len: usize) -> Self {
|
||||
let mut buf = Vec::new();
|
||||
buf.resize(len, 0u8);
|
||||
Self {
|
||||
buf,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn realloc(&mut self, new_len: usize) {
|
||||
self.buf.resize(new_len, 0u8);
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.buf.len()
|
||||
}
|
||||
|
||||
pub fn as_slice(&self) -> &[u8] {
|
||||
self.buf.as_ref()
|
||||
}
|
||||
|
||||
pub fn as_slice_mut(&mut self) -> &mut [u8] {
|
||||
self.buf.as_mut()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue