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.
20 21 22 |
# File 'lib/wasmtime/component.rb', line 20 def error(error) new(false, error) end |
.ok(ok) ⇒ Result
Construct an ok result.
13 14 15 |
# File 'lib/wasmtime/component.rb', line 13 def ok(ok) new(true, ok) end |
Instance Method Details
#==(other) ⇒ Object
55 56 57 |
# File 'lib/wasmtime/component.rb', line 55 def ==(other) eql?(other) end |
#eql?(other) ⇒ Boolean
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/wasmtime/component.rb', line 59 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.
39 40 41 42 43 |
# File 'lib/wasmtime/component.rb', line 39 def error raise UncheckedResult, "expected error, was ok" unless error? @value end |
#error? ⇒ Boolean
Returns Whether the result is an error.
51 52 53 |
# File 'lib/wasmtime/component.rb', line 51 def error? !@ok end |
#hash ⇒ Object
70 71 72 |
# File 'lib/wasmtime/component.rb', line 70 def hash [self.class, @ok, @value].hash end |
#ok ⇒ Object
Returns the ok value of this Result if it is #ok?, otherwise raises.
30 31 32 33 34 |
# File 'lib/wasmtime/component.rb', line 30 def ok raise UncheckedResult, "expected ok, was error" unless ok? @value end |
#ok? ⇒ Boolean
Returns Whether the result is ok.
46 47 48 |
# File 'lib/wasmtime/component.rb', line 46 def ok? @ok end |