mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.parser: add a generated .all(.flag1|.flag2) method to [flag] enums
Unlike `.has(.flag1|.flag2)`, which is true, for any of `.flag1` or `.flag2`, the new method `.all()` tests whether *all flags* are set at the same time.
This commit is contained in:
13
doc/docs.md
13
doc/docs.md
@@ -5344,14 +5344,23 @@ enum BitField {
|
||||
other
|
||||
}
|
||||
|
||||
fn example_enum_as_bitfield_use() {
|
||||
fn main() {
|
||||
assert 1 == int(BitField.read)
|
||||
assert 2 == int(BitField.write)
|
||||
mut bf := BitField.read
|
||||
assert bf.has(.read | .other) // test if *at least one* of the flags is set
|
||||
assert !bf.all(.read | .other) // test if *all* of the flags is set
|
||||
bf.set(.write | .other)
|
||||
assert bf.has(.read | .write | .other)
|
||||
assert bf.all(.read | .write | .other)
|
||||
bf.toggle(.other)
|
||||
assert bf == BitField.read | .write
|
||||
assert bf.all(.read | .write)
|
||||
assert !bf.has(.other)
|
||||
}
|
||||
```
|
||||
|
||||
```v
|
||||
// Calling this function will result in a deprecation warning
|
||||
[deprecated]
|
||||
fn old_function() {
|
||||
@@ -5372,7 +5381,9 @@ fn legacy_function() {}
|
||||
[deprecated: 'use new_function2() instead']
|
||||
[deprecated_after: '2021-05-27']
|
||||
fn legacy_function2() {}
|
||||
```
|
||||
|
||||
```v nofmt
|
||||
// This function's calls will be inlined.
|
||||
[inline]
|
||||
fn inlined_function() {
|
||||
|
||||
Reference in New Issue
Block a user