#How to make a type optional?

1 messages · Page 1 of 1 (latest)

open night
#

How to make a type optional?

#

given for example u8, turn it into ?u8

gleaming iron
#

you can just do ?T

bitter relic
#

so if you have a u8 you can just assign some ?u8 variable to it, or you can use @as to make it explicit

#
const non_optional: u8 = 5;
const optional1: ?u8 = non_optional
const optional2 = @as(?u8, non_optional);
const optional3 = @as(?u8, 10);