-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1903 from multiversx/static-flags
static api - initialization flags grouped into single bitfield
- Loading branch information
Showing
8 changed files
with
100 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
framework/base/src/api/managed_types/static_var_api_flags.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use bitflags::bitflags; | ||
|
||
bitflags! { | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
pub struct StaticVarApiFlags: u8 { | ||
const NONE = 0b00000000; | ||
const CALL_VALUE_EGLD_INITIALIZED = 0b00000001; | ||
const CALL_VALUE_EGLD_MULTI_INITIALIZED = 0b00000010; | ||
const CALL_VALUE_MULTI_ESDT_INITIALIZED = 0b00000100; | ||
const CALL_VALUE_ALL_INITIALIZED = 0b00001000; | ||
} | ||
} | ||
|
||
impl StaticVarApiFlags { | ||
pub fn check_and_set(&mut self, other: StaticVarApiFlags) -> bool { | ||
let contains_flag = self.contains(other); | ||
if !contains_flag { | ||
*self |= other; | ||
} | ||
contains_flag | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
pub mod tests { | ||
use super::StaticVarApiFlags; | ||
|
||
#[test] | ||
fn test_check_and_set() { | ||
let mut current = StaticVarApiFlags::NONE; | ||
|
||
assert!(current.check_and_set(StaticVarApiFlags::NONE)); | ||
assert_eq!(current, StaticVarApiFlags::NONE); | ||
|
||
assert!(!current.check_and_set(StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED)); | ||
assert_eq!(current, StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED); | ||
assert!(current.check_and_set(StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED)); | ||
assert_eq!(current, StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED); | ||
|
||
assert!(!current.check_and_set(StaticVarApiFlags::CALL_VALUE_ALL_INITIALIZED)); | ||
assert_eq!( | ||
current, | ||
StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED | ||
| StaticVarApiFlags::CALL_VALUE_ALL_INITIALIZED | ||
); | ||
assert!(current.check_and_set(StaticVarApiFlags::CALL_VALUE_ALL_INITIALIZED)); | ||
assert_eq!( | ||
current, | ||
StaticVarApiFlags::CALL_VALUE_EGLD_INITIALIZED | ||
| StaticVarApiFlags::CALL_VALUE_ALL_INITIALIZED | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters