module Change::TypeCast

Defined in:

change/typecast.cr
change/typecast/json.cr

Class Method Summary

Macro Summary

Class Method Detail

def self.cast(value : Nil, target : Nil.class) : Tuple(Bool, Nil | Nil) #

Nil


[View source]
def self.cast(value : JSON::Any, target : Nil.class) : Tuple(Bool, Nil | Nil) #

[View source]
def self.cast(value, target : Nil.class) : Tuple(Bool, Nil) #

Some other types have their own representations of nil (such as JSON::Any), so value is left untyped here.


[View source]
def self.cast(value : Nil, target : T.class) : Tuple(Bool, T | Nil) forall T #

Casting from nil is always considered valid to deal with field nilability. Non-nil assertions are instead made using validations.


[View source]
def self.cast(value : JSON::Any, target : Bool.class) : Tuple(Bool, Bool | Nil) #

[View source]
def self.cast(value, target : Bool.class) #

Booleans Boolean casts allow the strings "false" and "true" as their respective boolean values, but nothing else.


[View source]
def self.cast(value : JSON::Any, target : String.class) : Tuple(Bool, String | Nil) #

[View source]
def self.cast(value, target : String.class) : Tuple(Bool, String | Nil) #

Strings


[View source]
def self.cast(value : JSON::Any, target : Int32.class) : Tuple(Bool, Int32 | Nil) #

[View source]
def self.cast(value, target : Int32.class) : Tuple(Bool, Int32 | Nil) #

Integers


[View source]
def self.cast(value : JSON::Any, target : Int64.class) : Tuple(Bool, Int64 | Nil) #

[View source]
def self.cast(value, target : Int64.class) : Tuple(Bool, Int64 | Nil) #

[View source]
def self.cast(value : JSON::Any, target : Float32.class) : Tuple(Bool, Float32 | Nil) #

[View source]
def self.cast(value, target : Float32.class) : Tuple(Bool, Float32 | Nil) #

Floats


[View source]
def self.cast(value : JSON::Any, target : Float64.class) : Tuple(Bool, Float64 | Nil) #

[View source]
def self.cast(value, target : Float64.class) : Tuple(Bool, Float64 | Nil) #

[View source]
def self.cast(value : JSON::Any, target : Int.class) : Tuple(Bool, Int | Nil) #

[View source]
def self.cast(value : JSON::Any, target : Float.class) : Tuple(Bool, Float | Nil) #

[View source]

Macro Detail

macro def_cast(given, target) #

[View source]
macro method_cast(kind, method) #

Define a fallback cast method for all casts to a given type. This is mainly intended for primitive values and anything else that defines a converter on Object or things like JSON that cover most types automatically.

The value parameter is left untyped to allow overrides for specific value types to be defined afterward.


[View source]