-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
Transition
struct into its own module
- Loading branch information
Showing
4 changed files
with
43 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ pub mod events; | |
pub mod message; | ||
pub mod state; | ||
pub mod state_machine; | ||
pub mod transition; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use malachite_common::Context; | ||
|
||
use crate::message::Message; | ||
use crate::state::State; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct Transition<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
pub next_state: State<Ctx>, | ||
pub message: Option<Message<Ctx>>, | ||
pub valid: bool, | ||
} | ||
|
||
impl<Ctx> Transition<Ctx> | ||
where | ||
Ctx: Context, | ||
{ | ||
pub fn to(next_state: State<Ctx>) -> Self { | ||
Self { | ||
next_state, | ||
message: None, | ||
valid: true, | ||
} | ||
} | ||
|
||
pub fn invalid(next_state: State<Ctx>) -> Self { | ||
Self { | ||
next_state, | ||
message: None, | ||
valid: false, | ||
} | ||
} | ||
|
||
pub fn with_message(mut self, message: Message<Ctx>) -> Self { | ||
self.message = Some(message); | ||
self | ||
} | ||
} |