Skip to content

Commit 568d169

Browse files
cargo fmt
1 parent b11fafd commit 568d169

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

ext/ruby_wasm/src/lib.rs

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::{collections::HashMap, path::PathBuf};
22

33
use magnus::{
4-
eval, exception, function, method, prelude::*, value::{self, InnerValue}, wrap, Error, ExceptionClass, RModule, Ruby
4+
eval, exception, function, method,
5+
prelude::*,
6+
value::{self, InnerValue},
7+
wrap, Error, ExceptionClass, RModule, Ruby,
58
};
69
use structopt::StructOpt;
710
use wizer::Wizer;
@@ -48,16 +51,20 @@ impl WasiVfs {
4851
}
4952

5053
fn map_dir(&self, guest_dir: String, host_dir: String) {
51-
self.0.borrow_mut().map_dirs.push((guest_dir.into(), host_dir.into()));
54+
self.0
55+
.borrow_mut()
56+
.map_dirs
57+
.push((guest_dir.into(), host_dir.into()));
5258
}
5359

5460
fn pack(&self, wasm_bytes: bytes::Bytes) -> Result<bytes::Bytes, Error> {
55-
let output_bytes = wasi_vfs_cli::pack(&wasm_bytes, self.0.borrow().map_dirs.clone()).map_err(|e| {
56-
Error::new(
57-
exception::standard_error(),
58-
format!("failed to pack wasi vfs: {}", e),
59-
)
60-
})?;
61+
let output_bytes = wasi_vfs_cli::pack(&wasm_bytes, self.0.borrow().map_dirs.clone())
62+
.map_err(|e| {
63+
Error::new(
64+
exception::standard_error(),
65+
format!("failed to pack wasi vfs: {}", e),
66+
)
67+
})?;
6168
Ok(output_bytes.into())
6269
}
6370
}
@@ -67,9 +74,14 @@ struct ComponentLink(std::cell::RefCell<Option<wit_component::Linker>>);
6774

6875
impl ComponentLink {
6976
fn new() -> Self {
70-
Self(std::cell::RefCell::new(Some(wit_component::Linker::default())))
77+
Self(std::cell::RefCell::new(Some(
78+
wit_component::Linker::default(),
79+
)))
7180
}
72-
fn linker(&self, body: impl FnOnce(wit_component::Linker) -> Result<wit_component::Linker, Error>) -> Result<(), Error> {
81+
fn linker(
82+
&self,
83+
body: impl FnOnce(wit_component::Linker) -> Result<wit_component::Linker, Error>,
84+
) -> Result<(), Error> {
7385
let mut linker = self.0.take().ok_or_else(|| {
7486
Error::new(
7587
exception::standard_error(),
@@ -102,24 +114,16 @@ impl ComponentLink {
102114
})
103115
}
104116
fn validate(&self, validate: bool) -> Result<(), Error> {
105-
self.linker(|linker| {
106-
Ok(linker.validate(validate))
107-
})
117+
self.linker(|linker| Ok(linker.validate(validate)))
108118
}
109119
fn stack_size(&self, size: u32) -> Result<(), Error> {
110-
self.linker(|linker| {
111-
Ok(linker.stack_size(size))
112-
})
120+
self.linker(|linker| Ok(linker.stack_size(size)))
113121
}
114122
fn stub_missing_functions(&self, stub: bool) -> Result<(), Error> {
115-
self.linker(|linker| {
116-
Ok(linker.stub_missing_functions(stub))
117-
})
123+
self.linker(|linker| Ok(linker.stub_missing_functions(stub)))
118124
}
119125
fn use_built_in_libdl(&self, use_libdl: bool) -> Result<(), Error> {
120-
self.linker(|linker| {
121-
Ok(linker.use_built_in_libdl(use_libdl))
122-
})
126+
self.linker(|linker| Ok(linker.use_built_in_libdl(use_libdl)))
123127
}
124128
fn encode(&self) -> Result<bytes::Bytes, Error> {
125129
// Take the linker out of the cell and consume it
@@ -144,10 +148,17 @@ struct ComponentEncode(std::cell::RefCell<Option<wit_component::ComponentEncoder
144148

145149
impl ComponentEncode {
146150
fn new() -> Self {
147-
Self(std::cell::RefCell::new(Some(wit_component::ComponentEncoder::default())))
151+
Self(std::cell::RefCell::new(Some(
152+
wit_component::ComponentEncoder::default(),
153+
)))
148154
}
149155

150-
fn encoder(&self, body: impl FnOnce(wit_component::ComponentEncoder) -> Result<wit_component::ComponentEncoder, Error>) -> Result<(), Error> {
156+
fn encoder(
157+
&self,
158+
body: impl FnOnce(
159+
wit_component::ComponentEncoder,
160+
) -> Result<wit_component::ComponentEncoder, Error>,
161+
) -> Result<(), Error> {
151162
let mut encoder = self.0.take().ok_or_else(|| {
152163
Error::new(
153164
exception::standard_error(),
@@ -160,9 +171,7 @@ impl ComponentEncode {
160171
}
161172

162173
fn validate(&self, validate: bool) -> Result<(), Error> {
163-
self.encoder(|encoder| {
164-
Ok(encoder.validate(validate))
165-
})
174+
self.encoder(|encoder| Ok(encoder.validate(validate)))
166175
}
167176

168177
fn adapter(&self, name: String, module: bytes::Bytes) -> Result<(), Error> {
@@ -188,15 +197,11 @@ impl ComponentEncode {
188197
}
189198

190199
fn realloc_via_memory_grow(&self, realloc: bool) -> Result<(), Error> {
191-
self.encoder(|encoder| {
192-
Ok(encoder.realloc_via_memory_grow(realloc))
193-
})
200+
self.encoder(|encoder| Ok(encoder.realloc_via_memory_grow(realloc)))
194201
}
195202

196203
fn import_name_map(&self, map: HashMap<String, String>) -> Result<(), Error> {
197-
self.encoder(|encoder| {
198-
Ok(encoder.import_name_map(map))
199-
})
204+
self.encoder(|encoder| Ok(encoder.import_name_map(map)))
200205
}
201206

202207
fn encode(&self) -> Result<bytes::Bytes, Error> {
@@ -236,17 +241,29 @@ fn init(ruby: &Ruby) -> Result<(), Error> {
236241
component_link.define_method("adapter", method!(ComponentLink::adapter, 2))?;
237242
component_link.define_method("validate", method!(ComponentLink::validate, 1))?;
238243
component_link.define_method("stack_size", method!(ComponentLink::stack_size, 1))?;
239-
component_link.define_method("stub_missing_functions", method!(ComponentLink::stub_missing_functions, 1))?;
240-
component_link.define_method("use_built_in_libdl", method!(ComponentLink::use_built_in_libdl, 1))?;
244+
component_link.define_method(
245+
"stub_missing_functions",
246+
method!(ComponentLink::stub_missing_functions, 1),
247+
)?;
248+
component_link.define_method(
249+
"use_built_in_libdl",
250+
method!(ComponentLink::use_built_in_libdl, 1),
251+
)?;
241252
component_link.define_method("encode", method!(ComponentLink::encode, 0))?;
242253

243254
let component_encode = module.define_class("ComponentEncode", ruby.class_object())?;
244255
component_encode.define_singleton_method("new", function!(ComponentEncode::new, 0))?;
245256
component_encode.define_method("validate", method!(ComponentEncode::validate, 1))?;
246257
component_encode.define_method("adapter", method!(ComponentEncode::adapter, 2))?;
247258
component_encode.define_method("module", method!(ComponentEncode::module, 1))?;
248-
component_encode.define_method("realloc_via_memory_grow", method!(ComponentEncode::realloc_via_memory_grow, 1))?;
249-
component_encode.define_method("import_name_map", method!(ComponentEncode::import_name_map, 1))?;
259+
component_encode.define_method(
260+
"realloc_via_memory_grow",
261+
method!(ComponentEncode::realloc_via_memory_grow, 1),
262+
)?;
263+
component_encode.define_method(
264+
"import_name_map",
265+
method!(ComponentEncode::import_name_map, 1),
266+
)?;
250267
component_encode.define_method("encode", method!(ComponentEncode::encode, 0))?;
251268

252269
Ok(())

0 commit comments

Comments
 (0)