Class: Wasmtime::Component::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Class Method Details

.error(error) ⇒ Result

Construct an error result.

Parameters:

  • error (Object)

    the error value

Returns:



16
17
18
# File 'lib/wasmtime/component.rb', line 16

def error(error)
  new(false, error)
end

.ok(ok) ⇒ Result

Construct an ok result.

Parameters:

  • ok (Object)

    the ok value

Returns:



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

Returns:

  • (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

#errorObject

Returns the error value of this Result if it is #error?, otherwise raises.

Returns:

  • (Object)

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.

Returns:

  • (Boolean)

    Whether the result is an error



47
48
49
# File 'lib/wasmtime/component.rb', line 47

def error?
  !@ok
end

#hashObject



66
67
68
# File 'lib/wasmtime/component.rb', line 66

def hash
  [self.class, @ok, @value].hash
end

#okObject

Returns the ok value of this Result if it is #ok?, otherwise raises.

Returns:

  • (Object)

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.

Returns:

  • (Boolean)

    Whether the result is ok



42
43
44
# File 'lib/wasmtime/component.rb', line 42

def ok?
  @ok
end