Class: Wasmtime::WasiCtxBuilder

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

Overview

WASI context builder to be sent as Store.new’s wasi_ctx keyword argument.

Instance methods mutate the current object and return self.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newWasiCtxBuilder

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

Returns:



99
100
101
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 99

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

Instance Method Details

#inherit_stderrWasiCtxBuilder

Inherit stderr from the current Ruby process.

Returns:



172
173
174
175
176
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 172

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

#inherit_stdinWasiCtxBuilder

Inherit stdin from the current Ruby process.

Returns:



106
107
108
109
110
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 106

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

#inherit_stdoutWasiCtxBuilder

Inherit stdout from the current Ruby process.

Returns:



137
138
139
140
141
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 137

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) ⇒ WasiCtxBuilder

Set the arguments (argv) to the specified Array.

Parameters:

  • args (Array<String>)

Returns:



219
220
221
222
223
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 219

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) ⇒ WasiCtxBuilder

Set env to the specified Hash.

Parameters:

  • env (Hash<String, String>)

Returns:



208
209
210
211
212
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 208

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_stderr_buffer(buffer, capacity) ⇒ WasiCtxBuilder

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:



198
199
200
201
202
203
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 198

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) ⇒ WasiCtxBuilder

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:



184
185
186
187
188
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 184

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) ⇒ WasiCtxBuilder

Set stdin to read from the specified file.

Parameters:

  • path (String)

    The path of the file to read from.

Returns:



117
118
119
120
121
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 117

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) ⇒ WasiCtxBuilder

Set stdin to the specified String.

Parameters:

  • content (String)

Returns:



128
129
130
131
132
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 128

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) ⇒ WasiCtxBuilder

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:



163
164
165
166
167
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 163

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) ⇒ WasiCtxBuilder

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:



149
150
151
152
153
# File 'ext/src/ruby_api/wasi_ctx_builder.rs', line 149

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
}