module Change::TypeCast
Defined in:
change/typecast.crchange/typecast/json.cr
Class Method Summary
-
.cast(value : Nil, target : Nil.class) : Tuple(Bool, Nil | Nil)
Nil
- .cast(value : JSON::Any, target : Nil.class) : Tuple(Bool, Nil | Nil)
-
.cast(value, target : Nil.class) : Tuple(Bool, Nil)
Some other types have their own representations of nil (such as
JSON::Any
), sovalue
is left untyped here. -
.cast(value : Nil, target : T.class) : Tuple(Bool, T | Nil) forall T
Casting from nil is always considered valid to deal with field nilability.
- .cast(value : JSON::Any, target : Bool.class) : Tuple(Bool, Bool | Nil)
-
.cast(value, target : Bool.class)
Booleans Boolean casts allow the strings "false" and "true" as their respective boolean values, but nothing else.
- .cast(value : JSON::Any, target : String.class) : Tuple(Bool, String | Nil)
-
.cast(value, target : String.class) : Tuple(Bool, String | Nil)
Strings
- .cast(value : JSON::Any, target : Int32.class) : Tuple(Bool, Int32 | Nil)
-
.cast(value, target : Int32.class) : Tuple(Bool, Int32 | Nil)
Integers
- .cast(value : JSON::Any, target : Int64.class) : Tuple(Bool, Int64 | Nil)
- .cast(value, target : Int64.class) : Tuple(Bool, Int64 | Nil)
- .cast(value : JSON::Any, target : Float32.class) : Tuple(Bool, Float32 | Nil)
-
.cast(value, target : Float32.class) : Tuple(Bool, Float32 | Nil)
Floats
- .cast(value : JSON::Any, target : Float64.class) : Tuple(Bool, Float64 | Nil)
- .cast(value, target : Float64.class) : Tuple(Bool, Float64 | Nil)
- .cast(value : JSON::Any, target : Int.class) : Tuple(Bool, Int | Nil)
- .cast(value : JSON::Any, target : Float.class) : Tuple(Bool, Float | Nil)
Macro Summary
- def_cast(given, target)
-
method_cast(kind, method)
Define a fallback cast method for all casts to a given type.
Class Method Detail
Some other types have their own representations of nil (such as
JSON::Any
), so value
is left untyped here.
Casting from nil is always considered valid to deal with field nilability. Non-nil assertions are instead made using validations.
Booleans Boolean casts allow the strings "false" and "true" as their respective boolean values, but nothing else.
Macro Detail
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.