-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use types to represent a select strategy instead of a boolean
- Loading branch information
Showing
5 changed files
with
67 additions
and
32 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
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,25 @@ | ||
/// When used with a select future, this will make the future biased. | ||
/// When multiple futures are ready, the winner will be the first one | ||
/// specified. | ||
#[derive(Debug)] | ||
pub struct Biased; | ||
|
||
/// When used with a select future, this will make the future fair. | ||
/// When multiple futures are ready, the winner will be pseudo-randomly | ||
/// selected. This is the default behavior. | ||
#[derive(Debug)] | ||
pub struct Fair; | ||
|
||
/// Reports whether the type is an instance of [`Biased`] or not. | ||
pub trait IsBiased { | ||
/// Contains the answer to our question: is this biased? | ||
const IS_BIASED: bool; | ||
} | ||
|
||
impl IsBiased for Biased { | ||
const IS_BIASED: bool = true; | ||
} | ||
|
||
impl IsBiased for Fair { | ||
const IS_BIASED: bool = false; | ||
} |
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