-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add get_key_string method to RuntimeEvent #1107
Add get_key_string method to RuntimeEvent #1107
Conversation
let _event = RuntimeEvent::<DefaultContext>::second(second_test_module::Event::SecondModuleEnum); | ||
{ | ||
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::Event::FirstModuleEnum1(10)); | ||
assert_eq!(event.get_key_string(), "first-FirstModuleEnum1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this generate an expected string even if Event
is struct/tuple/array/nested enum
instead of an enum type?
|
||
{ | ||
let event = RuntimeEvent::<DefaultContext>::first(first_test_module::Event::FirstModuleEnum3(vec![1; 3])); | ||
assert_eq!(event.get_key_string(), "first-FirstModuleEnum3"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To create the key string using the get_key_string
function, we require a value of Event::FirstModuleEnum3(..)
. However, obtaining this value necessitates providing a Vec
this is fine when we save to the db.
Now, let's consider a scenario where a user wishes to query the database using the first-FirstModuleEnum3
key. What will be the method for the user to calculate the first-FirstModuleEnum3
? Since he doesn't have a value of the Event::FirstModuleEnum3(...)
he can't call get_key_string(&self)
. We have to think about the cases where the enums contain arbitrary complex structures and possibly other nested enums.
Closing in favor of: #1116 |
Description
Added a
get_key_string
method to the<runtime>Event
enum generated by theEvent
macro.This method will eventually be used to replace the user-defined event keys currently utilized for accessing events in the database.
Additionally, added the
Event
macro to thedemo_stf
runtime, and anEvent
enum to theValueSetter
module for testing purposes.Testing
Tested the new
get_key_string
method inderive_event.rs