Struct wasm_shrink::WasmShrink[][src]

pub struct WasmShrink { /* fields omitted */ }
Expand description

Shrink a Wasm file while maintaining a property of interest (such as triggering a compiler bug).

Example

use wasm_shrink::WasmShrink;

// Get the Wasm you want to shrink from somewhere.
let my_input_wasm: Vec<u8> = todo!();

// Configure the shrinking task.
let shrink = WasmShrink::default()
    // Give up on shrinking after 999 failed attempts to shrink a given
    // Wasm test case any further.
    .attempts(999);

// Run the configured shrinking task.
let info = shrink.run(
    my_input_wasm,
    // Predicate.
    &mut |wasm| {
        let is_interesting: bool = todo!(
            "check for whether the given Wasm is interesting"
        );
        Ok(is_interesting)
    },
    // Callback called each time we find a new smallest interesting
    // Wasm.
    &mut |new_smallest| {
        // Optionally do something with the new smallest Wasm.
        Ok(())
    },
)?;

// Get the shrunken Wasm and other information about the completed shrink
// task from the returned `ShrinkInfo`.
let shrunken_wasm = info.output;

Implementations

Set the number of shrink attempts to try before considering a Wasm module as small as it will ever get.

Is it okay to shrink the input down to an empty Wasm module?

This is usually not desired and typically reflects a bug in the predicate.

Set the RNG seed for choosing which size-reducing mutation to attempt next.

Run this configured Wasm shrinking task.

The predicate function is called on each candidate Wasm to determine whether the Wasm is interesting or not. Returning true means that it is interesting, false means that it is not.

The on_new_smallest function is called whenever we find a new smallest interesting Wasm.

Returns information and metrics about the shrink task, such as the shrunken Wasm’s output file path, the size of the input Wasm, the size of the output Wasm, etc.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.