Skip to content

Commit

Permalink
Merge pull request #54 from ewasm/utils
Browse files Browse the repository at this point in the history
Split out some utilities
  • Loading branch information
axic committed May 28, 2019
2 parents 2fff902 + 92ddc77 commit 11c18c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

mod native;
pub mod types;
mod utils;

#[cfg(feature = "debug")]
pub mod debug;
Expand All @@ -36,15 +37,7 @@ pub mod convert;
use std::vec::Vec;

use crate::types::*;

#[cfg(feature = "std")]
fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
let mut ret: Vec<u8> = Vec::with_capacity(len);
unsafe {
ret.set_len(len);
}
ret
}
use crate::utils::*;

/// Enum representing an error code for EEI calls. Currently used by `codeCopy`, `callDataCopy`,
/// `externalCodeCopy`, and `returnDataCopy`.
Expand Down
19 changes: 19 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[cfg(feature = "std")]
pub fn unsafe_alloc_buffer(len: usize) -> Vec<u8> {
let mut ret: Vec<u8> = Vec::with_capacity(len);
unsafe {
ret.set_len(len);
}
ret
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn smoke() {
let ret = unsafe_alloc_buffer(42);
assert_eq!(ret.len(), 42);
}
}

0 comments on commit 11c18c0

Please sign in to comment.