mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Return underlining value instead of panicing
when no name it found. Renamed use_enum_value_names to use_enum_names it get the same point across & inline with the reflect procs
This commit is contained in:
@@ -51,8 +51,10 @@ Marshal_Options :: struct {
|
|||||||
// NOTE: This will temp allocate and sort a list for each map.
|
// NOTE: This will temp allocate and sort a list for each map.
|
||||||
sort_maps_by_key: bool,
|
sort_maps_by_key: bool,
|
||||||
|
|
||||||
// Output enum value's name instead of its underlineing value
|
// Output enum value's name instead of its underlineing value.
|
||||||
use_enum_value_names: bool,
|
//
|
||||||
|
// NOTE: If a name isn't found it'll use the underlineing value.
|
||||||
|
use_enum_names: bool,
|
||||||
|
|
||||||
// Internal state
|
// Internal state
|
||||||
indentation: int,
|
indentation: int,
|
||||||
@@ -407,14 +409,14 @@ marshal_to_writer :: proc(w: io.Writer, v: any, opt: ^Marshal_Options) -> (err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
case runtime.Type_Info_Enum:
|
case runtime.Type_Info_Enum:
|
||||||
if !opt.use_enum_value_names || len(info.names) == 0 {
|
if !opt.use_enum_names || len(info.names) == 0 {
|
||||||
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
||||||
} else {
|
} else {
|
||||||
name, found := reflect.enum_name_from_value_any(v)
|
name, found := reflect.enum_name_from_value_any(v)
|
||||||
if found {
|
if found {
|
||||||
return marshal_to_writer(w, name, opt)
|
return marshal_to_writer(w, name, opt)
|
||||||
} else {
|
} else {
|
||||||
panic("Unable to find value in enum's values")
|
return marshal_to_writer(w, any{v.data, info.base.id}, opt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user