Skip to content

Commit

Permalink
Have transform take &self instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
samestep committed Jan 21, 2025
1 parent 000f6f3 commit dbb3858
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions crates/floretta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ impl Autodiff {
}

/// Transform a WebAssembly module using this configuration.
pub fn transform(self, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
self.runner.transform(self.config, wasm_module)
pub fn transform(&self, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
self.runner.transform(&self.config, wasm_module)
}
}

trait Runner {
fn transform(&self, config: Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error>;
fn transform(&self, config: &Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error>;
}

// We make `Runner` a `trait` instead of just an `enum`, to facilitate dead code elimination when
Expand All @@ -115,15 +115,15 @@ struct Validate;
struct NoValidate;

impl Runner for Validate {
fn transform(&self, config: Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
fn transform(&self, config: &Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
let features = WasmFeatures::empty() | WasmFeatures::FLOATS;
let validator = Validator::new_with_features(features);
run::transform(validator, config, wasm_module)
}
}

impl Runner for NoValidate {
fn transform(&self, config: Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
fn transform(&self, config: &Config, wasm_module: &[u8]) -> Result<Vec<u8>, Error> {
run::transform((), config, wasm_module)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/floretta/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{

pub fn transform(
mut validator: impl ModuleValidator,
config: Config,
config: &Config,
wasm_module: &[u8],
) -> Result<Vec<u8>, Error> {
let mut types = TypeSection::new();
Expand Down

0 comments on commit dbb3858

Please sign in to comment.