Class: Wasmtime::WasiCtx
- Inherits:
-
Object
- Object
- Wasmtime::WasiCtx
- Defined in:
- ext/src/ruby_api/wasi_ctx.rs
Overview
WASI context to be sent as Store.new’s wasi_ctx
keyword argument.
Instance methods mutate the current object and return self
.
Class Method Summary collapse
-
.deterministic ⇒ WasiCtx
Create a new deterministic WasiCtx.
Instance Method Summary collapse
-
#set_stderr_buffer(buffer, capacity) ⇒ WasiCtx
Set stderr to write to a string buffer.
-
#set_stderr_file(path) ⇒ WasiCtx
Set stderr to write to a file.
-
#set_stdin_file(path) ⇒ WasiCtxBuilder
Set stdin to read from the specified file.
-
#set_stdin_string(content) ⇒ WasiCtx
Set stdin to the specified String.
-
#set_stdout_buffer(buffer, capacity) ⇒ WasiCtx
Set stdout to write to a string buffer.
-
#set_stdout_file(path) ⇒ WasiCtx
Set stdout to write to a file.
Class Method Details
.deterministic ⇒ WasiCtx
Create a new deterministic Wasmtime::WasiCtx. See github.com/Shopify/deterministic-wasi-ctx for more details
35 36 37 38 39 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 35
pub fn deterministic() -> Self {
Self {
inner: RefCell::new(wasi_deterministic_ctx()),
}
}
|
Instance Method Details
#set_stderr_buffer(buffer, capacity) ⇒ WasiCtx
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
115 116 117 118 119 120 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 115
fn set_stderr_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let pipe = WritePipe::new(OutputLimitedBuffer::new(buffer.into(), capacity));
inner.set_stderr(Box::new(pipe));
rb_self
}
|
#set_stderr_file(path) ⇒ WasiCtx
Set stderr to write to a file. Will truncate the file if it exists, otherwise try to create it.
100 101 102 103 104 105 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 100
fn set_stderr_file(rb_self: RbSelf, path: RString) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let cs = file_w(path).map(wasi_file).unwrap();
inner.set_stderr(cs);
rb_self
}
|
#set_stdin_file(path) ⇒ WasiCtxBuilder
Set stdin to read from the specified file.
46 47 48 49 50 51 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 46
fn set_stdin_file(rb_self: RbSelf, path: RString) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let cs = file_r(path).map(wasi_file).unwrap();
inner.set_stdin(cs);
rb_self
}
|
#set_stdin_string(content) ⇒ WasiCtx
Set stdin to the specified String.
58 59 60 61 62 63 64 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 58
fn set_stdin_string(rb_self: RbSelf, content: RString) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let str = unsafe { content.as_slice() };
let pipe = ReadPipe::from(str);
inner.set_stdin(Box::new(pipe));
rb_self
}
|
#set_stdout_buffer(buffer, capacity) ⇒ WasiCtx
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
87 88 89 90 91 92 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 87
fn set_stdout_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let pipe = WritePipe::new(OutputLimitedBuffer::new(buffer.into(), capacity));
inner.set_stdout(Box::new(pipe));
rb_self
}
|
#set_stdout_file(path) ⇒ WasiCtx
Set stdout to write to a file. Will truncate the file if it exists, otherwise try to create it.
72 73 74 75 76 77 |
# File 'ext/src/ruby_api/wasi_ctx.rs', line 72
fn set_stdout_file(rb_self: RbSelf, path: RString) -> RbSelf {
let inner = rb_self.inner.borrow_mut();
let cs = file_w(path).map(wasi_file).unwrap();
inner.set_stdout(cs);
rb_self
}
|