From 47278b4a7dd4b417613338107d6a0753e5fbd771 Mon Sep 17 00:00:00 2001 From: Larpon Date: Mon, 23 Aug 2021 13:23:59 +0200 Subject: [PATCH] doc: document [flag] enum attribute (#11282) --- doc/docs.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/docs.md b/doc/docs.md index 41837dd763..0864175d75 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -5306,6 +5306,23 @@ An attribute is a compiler instruction specified inside `[]` right before a function/struct/enum declaration and applies only to the following declaration. ```v +// [flag] enables Enum types to be used as bitfields + +[flag] +enum BitField { + read + write + other +} + +fn example_enum_as_bitfield_use() { + assert 1 == int(BitField.read) + assert 2 == int(BitField.write) + mut bf := BitField.read + bf.set(.write | .other) + assert bf.has(.read | .write | .other) +} + // Calling this function will result in a deprecation warning [deprecated] fn old_function() {