struct Union(*T)

Overview

A union type represents the possibility of a variable or an expression having more than one possible type at compile time.

When invoking a method on a union type, the language checks that the method exists and can be resolved (typed) for each type in the union. For this reason, adding instance methods to Union makes no sense and has no effect. However, adding class method to Union is possible and can be useful. One example is parsing JSON into one of many possible types.

Union is special in that it is a generic type but instantiating it might not return a union type:

Union(Int32 | String)      # => (Int32 | String)
Union(Int32)               # => Int32
Union(Int32, Int32, Int32) # => Int32

Defined in:

ssz/codec.cr
ssz/hash_tree_root.cr

Class Method Summary

Instance methods inherited from class Object

ssz_basic? : Bool ssz_basic?, ssz_encode(io : IO)
ssz_encode : Bytes
ssz_encode
, ssz_fixed? : Bool ssz_fixed?, ssz_size : Int32 ssz_size, ssz_variable? : Bool ssz_variable?

Class methods inherited from class Object

ssz_basic? : Bool ssz_basic?, ssz_decode(io : IO, size : Int32 = 0)
ssz_decode(bytes : Bytes)
ssz_decode
, ssz_fixed? : Bool ssz_fixed?, ssz_variable? : Bool ssz_variable?

Class Method Detail

def self.hash_tree_root(value : self) : Bytes #

[View source]
def self.ssz_basic? : Bool #

[View source]
def self.ssz_decode(io : IO, size : Int32 = 0) #

[View source]
def self.ssz_encode(io : IO, value : self) #

[View source]
def self.ssz_encode(value : self) : Bytes #

[View source]
def self.ssz_fixed? : Bool #

[View source]
def self.ssz_size(value : self) : Int32 #

[View source]
def self.ssz_type_index(value : self) : SSZ::Offset #

[View source]
def self.ssz_variable? : Bool #

[View source]