fn compute_stack_cost(func_idx: u32, module: &elements::Module) -> Result<u32, Error> {
	// To calculate the cost of a function we need to convert index from
	// function index space to defined function spaces.
	let func_imports = module.import_count(elements::ImportCountType::Function) as u32;
	let defined_func_idx = func_idx.checked_sub(func_imports).ok_or_else(|| {
		Error("This should be a index of a defined function".into())
	})?;

	let code_section = module.code_section().ok_or_else(|| {
		Error("Due to validation code section should exists".into())
	})?;
	let body = &code_section
		.bodies()
		.get(defined_func_idx as usize)
		.ok_or_else(|| Error("Function body is out of bounds".into()))?;
	let locals_count = body.locals().len() as u32;

	let max_stack_height =
		max_height::compute(
			defined_func_idx,
			module
		)?;

	Ok(locals_count + max_stack_height)
}
/// Stack cost of the given *defined* function is the sum of it's locals count (that is,
/// number of arguments plus number of local variables) and the maximal stack
/// height.
Stack cost of the given *defined* function is the sum of it's locals count (that is,
number of arguments plus number of local variables) and the maximal stack
height.
Stack cost of the given * defined * function is the sum of it ' s locals count ( that is number of arguments plus number of local variables ) and the maximal stack height .
fn compute_stack_cost(func_idx: u32, module: &elements::Module) -> Result<u32, Error> {
	// To calculate the cost of a function we need to convert index from
	// function index space to defined function spaces.
	let func_imports = module.import_count(elements::ImportCountType::Function) as u32;
	let defined_func_idx = func_idx.checked_sub(func_imports).ok_or_else(|| {
		Error("This should be a index of a defined function".into())
	})?;
	let code_section = module.code_section().ok_or_else(|| {
		Error("Due to validation code section should exists".into())
	})?;
	let body = &code_section
		.bodies()
		.get(defined_func_idx as usize)
		.ok_or_else(|| Error("Function body is out of bounds".into()))?;
	let locals_count = body.locals().len() as u32;
	let max_stack_height =
		max_height::compute(
			defined_func_idx,
			module
		)?;
	Ok(locals_count + max_stack_height)
}
fn compute_stack_cost ( func_idx : u32 , module : & elements :: Module ) -> Result < u32 , Error > { // To calculate the cost of a function we need to convert index from // function index space to defined function spaces. let func_imports = module . import_count ( elements :: ImportCountType :: Function ) as u32 ; let defined_func_idx = func_idx . checked_sub ( func_imports ) . ok_or_else ( | | { Error ( " " . into ( ) ) } ) ? ; let code_section = module . code_section ( ) . ok_or_else ( | | { Error ( " " . into ( ) ) } ) ? ; let body = & code_section . bodies ( ) . get ( defined_func_idx as usize ) . ok_or_else ( | | Error ( " " . into ( ) ) ) ? ; let locals_count = body . locals ( ) . len ( ) as u32 ; let max_stack_height = max_height :: compute ( defined_func_idx , module ) ? ; Ok ( locals_count + max_stack_height ) }
Stack cost of the given *defined* function is the sum of it's locals count (that is,
number of arguments plus number of local variables) and the maximal stack
height.
Stack cost of the given * defined * function is the sum of it ' s locals count ( that is number of arguments plus number of local variables ) and the maximal stack height .
func_idx
u32
module
&elements::Module
func_idx
u32
module
&elements::Module