-
Notifications
You must be signed in to change notification settings - Fork 31
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
Pass reference values in guards and owned values in actions #49
Conversation
Let me know if you have any comments |
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.
The changes seem reasonable to me. This will definitely have some impact on fallible actions support though discussed in #44, but I don't think that should block a change like this. There's definitely value in simply moving data instead of using references and letting the compiler be smart about copying/cloning as appropriate.
Pushed new changes. I avoided panicking, however If you have any other ideas let me know. |
I had an idea today to introduce These are the reasons that this error will happen:
This is the generated code: #[inline(always)]
pub fn state(&self) -> Result<&States, Error> {
self.state.as_ref().ok_or_else(|| Error::Poisoned)
}
pub fn process_event(&mut self, mut event: Events) -> Result<&States, Error> {
match self.state.take().ok_or_else(|| Error::Poisoned)? {
States::State1 => match event {
Events::Event1(event_data) => {
match self.context.guard1(&event_data) {
Ok(()) => {
let _data = self.context.action1(event_data);
self.state = Some(States::State2(_data));
}
Err(e) => {
self.state = Some(States::State1);
return Err(Error::GuardFailed(e));
}
}
self.state()
}
_ => {
self.state = Some(States::State1);
Err(Error::InvalidEvent)
}
},
States::State2(state_data) => match event {
_ => {
self.state = Some(States::State2(state_data));
Err(Error::InvalidEvent)
}
},
state => {
self.state = Some(state);
Err(Error::InvalidEvent)
}
}
} |
Rebased. Now the generated code is: pub fn state(&self) -> Result<&States, Error> {
self.state.as_ref().ok_or_else(|| Error::Poisoned)
}
pub fn process_event(&mut self, mut event: Events) -> Result<&States, Error> {
match self.state.take().ok_or_else(|| Error::Poisoned)? {
States::State1 => match event {
Events::Event1(event_data) => {
if let Err(e) = self.context.guard1(&event_data) {
self.state = Some(States::State1);
return Err(Error::GuardFailed(e));
}
let _data = self.context.action1(event_data);
self.state = Some(States::State2(_data));
self.state()
}
_ => {
self.state = Some(States::State1);
Err(Error::InvalidEvent)
}
},
States::State2(state_data) => match event {
_ => {
self.state = Some(States::State2(state_data));
Err(Error::InvalidEvent)
}
},
state => {
self.state = Some(state);
Err(Error::InvalidEvent)
}
}
} |
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.
I'd like to let this kind of change rest for a bit before releasing it. There's some implications of moving state data that I'm not sure I've fully understood yet.
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.
LGTM. Thanks for persisting through my nagging :)
Closes #48