Class: Wasmtime::Component::Result
- Inherits:
-
Object
- Object
- Wasmtime::Component::Result
- Defined in:
- lib/wasmtime/component.rb
Overview
Represents a component model’s result<O, E> type.
Defined Under Namespace
Classes: UncheckedResult
Class Method Summary collapse
-
.error(error) ⇒ Result
Construct an error result.
-
.ok(ok) ⇒ Result
Construct an ok result.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
-
#error ⇒ Object
Returns the error value of this Result if it is #error?, otherwise raises.
-
#error? ⇒ Boolean
Whether the result is an error.
- #hash ⇒ Object
-
#ok ⇒ Object
Returns the ok value of this Result if it is #ok?, otherwise raises.
-
#ok? ⇒ Boolean
Whether the result is ok.
Class Method Details
.error(error) ⇒ Result
Construct an error result.
16 17 18 |
# File 'lib/wasmtime/component.rb', line 16 def error(error) new(false, error) end |
.ok(ok) ⇒ Result
Construct an ok result.
9 10 11 |
# File 'lib/wasmtime/component.rb', line 9 def ok(ok) new(true, ok) end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 |
# File 'lib/wasmtime/component.rb', line 51 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wasmtime/component.rb', line 55 def eql?(other) return false unless self.class == other.class return false unless ok? == other.ok? if ok? ok == other.ok else error == other.error end end |
#error ⇒ Object
Returns the error value of this Result if it is #error?, otherwise raises.
35 36 37 38 39 |
# File 'lib/wasmtime/component.rb', line 35 def error raise UncheckedResult, "expected error, was ok" unless error? @value end |
#error? ⇒ Boolean
Returns Whether the result is an error.
47 48 49 |
# File 'lib/wasmtime/component.rb', line 47 def error? !@ok end |
#hash ⇒ Object
66 67 68 |
# File 'lib/wasmtime/component.rb', line 66 def hash [self.class, @ok, @value].hash end |
#ok ⇒ Object
Returns the ok value of this Result if it is #ok?, otherwise raises.
26 27 28 29 30 |
# File 'lib/wasmtime/component.rb', line 26 def ok raise UncheckedResult, "expected ok, was error" unless ok? @value end |
#ok? ⇒ Boolean
Returns Whether the result is ok.
42 43 44 |
# File 'lib/wasmtime/component.rb', line 42 def ok? @ok end |