Box

class Box(T)

Overview

A Box allows turning any object to a Void* and back.

A Box's purpose is passing data to C as a Void* and then converting that back to the original data type.

For an example usage, see Proc's explanation about sending Procs to C.

Defined in:

box.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.box(object) : Pointer(Void)Source

Creates a Box for an object and returns it as a Void*.

def self.new(object : T)Source

Creates a Box with the given object-

This method isn't usually used directly- Instead, Box.box is used.

def self.unbox(pointer : Pointer(Void)) : TSource

Unboxes a Void* into an object of type T. Note that for this you must specify T: Box(T).unbox(data).

Instance Method Detail

def object : TSource

Returns the original object

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/Box.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部