-
Notifications
You must be signed in to change notification settings - Fork 544
react: Distinguish cell IDs #499
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,7 +1,30 @@ | ||
// Because these are passed without & to some functions, | ||
// it will probably be necessary for these two types to be Copy. | ||
pub type CellID = (); | ||
pub type CallbackID = (); | ||
/// `InputCellID` is a unique identifier for an input cell. | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct InputCellID(); | ||
/// `ComputeCellID` is a unique identifier for a compute cell. | ||
/// Values of type `InputCellID` and `ComputeCellID` should not be mutually assignable, | ||
/// demonstrated by the following tests: | ||
/// | ||
/// ```compile_fail | ||
/// let mut r = react::Reactor::new(); | ||
/// let input: react::ComputeCellID = r.create_input(111); | ||
/// ``` | ||
/// | ||
/// ```compile_fail | ||
/// let mut r = react::Reactor::new(); | ||
/// let input = r.create_input(111); | ||
/// let compute: react::InputCellID = r.create_compute(&[react::CellID::Input(input)], |_| 222).unwrap(); | ||
/// ``` | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub struct ComputeCellID(); | ||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that the tests are going to need all of these. The reason why The reason for Copy (and therefore why Clone) is:
|
||
pub struct CallbackID(); | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq)] | ||
pub enum CellID { | ||
Input(InputCellID), | ||
Compute(ComputeCellID), | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum SetValueError { | ||
|
@@ -28,7 +51,7 @@ impl <T: Copy + PartialEq> Reactor<T> { | |
} | ||
|
||
// Creates an input cell with the specified initial value, returning its ID. | ||
pub fn create_input(&mut self, _initial: T) -> CellID { | ||
pub fn create_input(&mut self, _initial: T) -> InputCellID { | ||
unimplemented!() | ||
} | ||
|
||
|
@@ -45,7 +68,7 @@ impl <T: Copy + PartialEq> Reactor<T> { | |
// Notice that there is no way to *remove* a cell. | ||
// This means that you may assume, without checking, that if the dependencies exist at creation | ||
// time they will continue to exist as long as the Reactor exists. | ||
pub fn create_compute<F: Fn(&[T]) -> T>(&mut self, _dependencies: &[CellID], _compute_func: F) -> Result<CellID, CellID> { | ||
pub fn create_compute<F: Fn(&[T]) -> T>(&mut self, _dependencies: &[CellID], _compute_func: F) -> Result<ComputeCellID, CellID> { | ||
unimplemented!() | ||
} | ||
|
||
|
@@ -71,7 +94,7 @@ impl <T: Copy + PartialEq> Reactor<T> { | |
// a `set_value(&mut self, new_value: T)` method on `Cell`. | ||
// | ||
// As before, that turned out to add too much extra complexity. | ||
pub fn set_value(&mut self, _id: CellID, _new_value: T) -> Result<(), SetValueError> { | ||
pub fn set_value(&mut self, _id: InputCellID, _new_value: T) -> Result<(), SetValueError> { | ||
unimplemented!() | ||
} | ||
|
||
|
@@ -87,7 +110,7 @@ impl <T: Copy + PartialEq> Reactor<T> { | |
// * Exactly once if the compute cell's value changed as a result of the set_value call. | ||
// The value passed to the callback should be the final value of the compute cell after the | ||
// set_value call. | ||
pub fn add_callback<F: FnMut(T) -> ()>(&mut self, _id: CellID, _callback: F) -> Option<CallbackID> { | ||
pub fn add_callback<F: FnMut(T) -> ()>(&mut self, _id: ComputeCellID, _callback: F) -> Option<CallbackID> { | ||
unimplemented!() | ||
} | ||
|
||
|
@@ -96,7 +119,7 @@ impl <T: Copy + PartialEq> Reactor<T> { | |
// Returns an Err if either the cell or callback does not exist. | ||
// | ||
// A removed callback should no longer be called. | ||
pub fn remove_callback(&mut self, cell: CellID, callback: CallbackID) -> Result<(), RemoveCallbackError> { | ||
pub fn remove_callback(&mut self, cell: ComputeCellID, callback: CallbackID) -> Result<(), RemoveCallbackError> { | ||
unimplemented!( | ||
"Remove the callback identified by the CallbackID {:?} from the cell {:?}", | ||
callback, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure if
cargo doc
flags to the user that the code under test here should fail to compile. If it does, no changes are required. If it does not, it's probably worth mentioning in the text that both of the examples here should fail to compile.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 did manage to confirm this. There's a red ⓘ and hovering over it shows "this example deliberately fails to compile"
Given this, I'll be merging it. Just not now, since it is inconvenient to now.