There was an error while loading. Please reload this page.
User defined casts can be created by defining a function named __as__, with an argument of the "from" type and a return type of the "to" type:
__as__
func __as__(from FromType) ToType { // ... }
By default, user-defined casts only occur when as or cast is used on a value of the "from" type:
as
cast
from as ToType cast ToType from
In order for conversion between two types to be implicit and not require as or cast, you can use the implicit keyword when defining the conversion:
implicit
implicit func __as__(from FromType) ToType { // ... }
This will allow for values of type FromType to be automatically converted to the type ToType.
FromType
ToType
User-defined conversions can be manually invoked using the ~> operator to specify the return type:
~>
__as__(from) ~> ToType
Table of Contents