std/box
import std/box to use it. Source: src/std/box.iyi at v0.18.0.
A Box's purpose is passing data to C as a Void* and then converting that back to the original data type.
For example, sending Procs or context to C callbacks.
Box(T)class
pub class Box(T)
# Turns object into a Void*.
#
# Copies object to the heap inside a Box container if needed.
def self.box(object : T) : ::Pointer(Void)
def initialize(object : T)
def object : T
# Unboxes a Void* into an object of type T.
#
# Specifying T is required: `Box(T).unbox(data)`. A null pointer is nil
# when T admits nil, as the other library answers it for `String?` and
# every other union of references and nil, and is refused otherwise. It
# was refused for every T, so `Box(String?).unbox` of the null a C
# callback is handed when there is no data panicked "Unboxing null
# pointer" where nil is the answer the type has room for.
def self.unbox(pointer : ::Pointer(Void)) : T
end
Box allows turning any object to a Void* and back.