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:



20
21
22
# File 'lib/wasmtime/component.rb', line 20

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

.ok(ok) ⇒ Result

Construct an ok result.

Parameters:

  • ok (Object)

    the ok value

Returns:



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

Returns:

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

#errorObject

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

Returns:

  • (Object)

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.

Returns:

  • (Boolean)

    Whether the result is an error



51
52
53
# File 'lib/wasmtime/component.rb', line 51

def error?
  !@ok
end

#hashObject



70
71
72
# File 'lib/wasmtime/component.rb', line 70

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:



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.

Returns:

  • (Boolean)

    Whether the result is ok



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

def ok?
  @ok
end