Class: Wasmtime::Component::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/wasmtime/component.rb

Overview

Represents a value for component model’s variant case. A variant case has a name that uniquely identify the case within the variant and optionally a value.

Examples:

Constructing variants

# Given the following variant:
# variant filter {
#     all,
#     none,
#     lt(u32),
# }

Variant.new("all")
Variant.new("none")
Variant.new("lt", 100)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = nil) ⇒ Variant

Returns a new instance of Variant.

Parameters:

  • name (String)

    the name of variant case

  • value (Object) (defaults to: nil)

    the optional payload of the variant case



112
113
114
115
# File 'lib/wasmtime/component.rb', line 112

def initialize(name, value = nil)
  @name = name
  @value = value
end

Instance Attribute Details

#nameString (readonly)

The name of the variant case

Returns:

  • (String)


104
105
106
# File 'lib/wasmtime/component.rb', line 104

def name
  @name
end

#valueObject (readonly)

The optional payload of the variant case

Returns:

  • (Object)


108
109
110
# File 'lib/wasmtime/component.rb', line 108

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



117
118
119
# File 'lib/wasmtime/component.rb', line 117

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
124
125
# File 'lib/wasmtime/component.rb', line 121

def eql?(other)
  self.class == other.class &&
    name == other.name &&
    value == other.value
end

#hashObject



127
128
129
# File 'lib/wasmtime/component.rb', line 127

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