This commit is contained in:
Sergey Pepyakin 2019-04-18 14:59:06 +02:00
parent 8a654554d1
commit 7d1d6efe38
1 changed files with 9 additions and 14 deletions

View File

@ -110,21 +110,16 @@ impl MemoryInstance {
pub fn alloc(initial: Pages, maximum: Option<Pages>) -> Result<MemoryRef, Error> {
{
use std::convert::TryInto;
let initial_u32: u32 = initial
.0
.try_into()
.map_err(|_| Error::Memory(format!("initial ({}) can't be coerced to u32", initial.0)))?;
let initial_u32: u32 = initial.0.try_into().map_err(|_| {
Error::Memory(format!("initial ({}) can't be coerced to u32", initial.0))
})?;
let maximum_u32: Option<u32> = match maximum {
Some(maximum_pages) => Some(
maximum_pages
.0
.try_into()
.map_err(|_|
Error::Memory(
format!("maximum ({}) can't be coerced to u32", maximum_pages.0)
)
)?,
),
Some(maximum_pages) => Some(maximum_pages.0.try_into().map_err(|_| {
Error::Memory(format!(
"maximum ({}) can't be coerced to u32",
maximum_pages.0
))
})?),
None => None,
};
validation::validate_memory(initial_u32, maximum_u32).map_err(Error::Memory)?;