Class: Wasmtime::WasiConfig

Inherits:
Object
  • Object
show all
Defined in:
ext/src/ruby_api/wasi_config.rs

Overview

WASI config to be sent as Store.new’s wasi_config keyword argument.

Instance methods mutate the current object and return self.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newWasiConfig

Create a new Wasmtime::WasiConfig. By default, it has nothing: no stdin/out/err, no env, no argv, no file access.

Returns:



174
175
176
# File 'ext/src/ruby_api/wasi_config.rs', line 174

pub fn new() -> Self {
    Self::default()
}

Instance Method Details

#add_determinismWasiConfig

Use deterministic implementations for clocks and random methods.

Returns:



181
182
183
184
185
# File 'ext/src/ruby_api/wasi_config.rs', line 181

pub fn add_determinism(rb_self: RbSelf) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.deterministic = true;
    rb_self
}

#inherit_stderrWasiConfig

Inherit stderr from the current Ruby process.

Returns:



256
257
258
259
260
# File 'ext/src/ruby_api/wasi_config.rs', line 256

pub fn inherit_stderr(rb_self: RbSelf) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stderr = Some(WriteStream::Inherit);
    rb_self
}

#inherit_stdinWasiConfig

Inherit stdin from the current Ruby process.

Returns:



190
191
192
193
194
# File 'ext/src/ruby_api/wasi_config.rs', line 190

pub fn inherit_stdin(rb_self: RbSelf) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdin = Some(ReadStream::Inherit);
    rb_self
}

#inherit_stdoutWasiConfig

Inherit stdout from the current Ruby process.

Returns:



221
222
223
224
225
# File 'ext/src/ruby_api/wasi_config.rs', line 221

pub fn inherit_stdout(rb_self: RbSelf) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdout = Some(WriteStream::Inherit);
    rb_self
}

#set_argv(args) ⇒ WasiConfig

Set the arguments (argv) to the specified Array.

Parameters:

  • args (Array<String>)

Returns:



303
304
305
306
307
# File 'ext/src/ruby_api/wasi_config.rs', line 303

pub fn set_argv(rb_self: RbSelf, argv: RArray) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.args = Some(argv.into());
    rb_self
}

#set_env(env) ⇒ WasiConfig

Set env to the specified Hash.

Parameters:

  • env (Hash<String, String>)

Returns:



292
293
294
295
296
# File 'ext/src/ruby_api/wasi_config.rs', line 292

pub fn set_env(rb_self: RbSelf, env: RHash) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.env = Some(env.into());
    rb_self
}

#set_mapped_directory(host_path, guest_path, dir_perms, file_perms) ⇒ WasiConfig

Set mapped directory for host path and guest path.

Parameters:

  • host_path (String)
  • guest_path (String)
  • dir_perms (Symbol)

    Directory permissions, one of :read, :mutate, or :all

  • file_perms (Symbol)

    File permissions, one of :read, :write, or :all

Returns:



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'ext/src/ruby_api/wasi_config.rs', line 317

pub fn set_mapped_directory(
    rb_self: RbSelf,
    host_path: RString,
    guest_path: RString,
    dir_perms: Symbol,
    file_perms: Symbol,
) -> RbSelf {
    let mapped_dir = MappedDirectory {
        host_path: host_path.into(),
        guest_path: guest_path.into(),
        dir_perms: dir_perms.into(),
        file_perms: file_perms.into(),
    };

    let mut inner = rb_self.inner.borrow_mut();
    inner.mapped_directories.push(mapped_dir);

    rb_self
}

#set_stderr_buffer(buffer, capacity) ⇒ WasiConfig

Set stderr to write to a string buffer. If the string buffer is frozen, Wasm execution will raise a Wasmtime::Error error. No encoding checks are done on the resulting string, it is the caller’s responsibility to ensure the string contains a valid encoding

Parameters:

  • buffer (String)

    The string buffer to write to.

  • capacity (Integer)

    The maximum number of bytes that can be written to the output buffer.

Returns:



282
283
284
285
286
287
# File 'ext/src/ruby_api/wasi_config.rs', line 282

pub fn set_stderr_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stderr = Some(WriteStream::Buffer(buffer.into(), capacity));
    rb_self
}
/// @yard

#set_stderr_file(path) ⇒ WasiConfig

Set stderr to write to a file. Will truncate the file if it exists, otherwise try to create it.

Parameters:

  • path (String)

    The path of the file to write to.

Returns:



268
269
270
271
272
# File 'ext/src/ruby_api/wasi_config.rs', line 268

pub fn set_stderr_file(rb_self: RbSelf, path: RString) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stderr = Some(WriteStream::Path(path.into()));
    rb_self
}

#set_stdin_file(path) ⇒ WasiConfig

Set stdin to read from the specified file.

Parameters:

  • path (String)

    The path of the file to read from.

Returns:



201
202
203
204
205
# File 'ext/src/ruby_api/wasi_config.rs', line 201

pub fn set_stdin_file(rb_self: RbSelf, path: RString) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdin = Some(ReadStream::Path(path.into()));
    rb_self
}

#set_stdin_string(content) ⇒ WasiConfig

Set stdin to the specified String.

Parameters:

  • content (String)

Returns:



212
213
214
215
216
# File 'ext/src/ruby_api/wasi_config.rs', line 212

pub fn set_stdin_string(rb_self: RbSelf, content: RString) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdin = Some(ReadStream::String(content.into()));
    rb_self
}

#set_stdout_buffer(buffer, capacity) ⇒ WasiConfig

Set stdout to write to a string buffer. If the string buffer is frozen, Wasm execution will raise a Wasmtime::Error error. No encoding checks are done on the resulting string, it is the caller’s responsibility to ensure the string contains a valid encoding

Parameters:

  • buffer (String)

    The string buffer to write to.

  • capacity (Integer)

    The maximum number of bytes that can be written to the output buffer.

Returns:



247
248
249
250
251
# File 'ext/src/ruby_api/wasi_config.rs', line 247

pub fn set_stdout_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdout = Some(WriteStream::Buffer(buffer.into(), capacity));
    rb_self
}

#set_stdout_file(path) ⇒ WasiConfig

Set stdout to write to a file. Will truncate the file if it exists, otherwise try to create it.

Parameters:

  • path (String)

    The path of the file to write to.

Returns:



233
234
235
236
237
# File 'ext/src/ruby_api/wasi_config.rs', line 233

pub fn set_stdout_file(rb_self: RbSelf, path: RString) -> RbSelf {
    let mut inner = rb_self.inner.borrow_mut();
    inner.stdout = Some(WriteStream::Path(path.into()));
    rb_self
}