mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Add @enum_from_value
This commit is contained in:
@@ -235,6 +235,24 @@ macro enum_by_name($Type, String enum_name) @builtin
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
<*
|
||||
@param $Type `The type of the enum`
|
||||
@require $Type.kindof == ENUM `Only enums may be used`
|
||||
@require $defined($Type.#value1) `Expected '#value' to match an enum associated value`
|
||||
@require $assignable(value, $typeof($Type{}.#value)) `Expected the value to match the type of the associated value`
|
||||
@ensure @typeis(return, $Type)
|
||||
@return! SearchResult.MISSING
|
||||
*>
|
||||
macro @enum_from_value($Type, #value, value) @builtin
|
||||
{
|
||||
usz elements = $Type.elements;
|
||||
foreach (e : $Type.values)
|
||||
{
|
||||
if (e.#value == value) return e;
|
||||
}
|
||||
return SearchResult.MISSING?;
|
||||
}
|
||||
|
||||
<*
|
||||
Mark an expression as likely to be true
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
- Added `iter()` `value_iter()` and `key_iter()` to HashMap.
|
||||
- Add "tokenizer" to String.
|
||||
- Add "skip_empty" to split methods. Add split_to_buffer method.
|
||||
- Add `@enum_from_value`.
|
||||
|
||||
## 0.6.5 Change list
|
||||
|
||||
|
||||
Reference in New Issue
Block a user