IO implementation for embedded-io#101
IO implementation for embedded-io#101Artur-Romaniuk wants to merge 4 commits intorust-embedded:mainfrom
Conversation
newAM
left a comment
There was a problem hiding this comment.
Looks good, thanks for adding the feature, just some structural changes I would make.
There was a problem hiding this comment.
This should go under src/io.rs since embedded-io is versioned independently of embedded-hal.
There was a problem hiding this comment.
@dbrgn If you could give your opinion on this?
There was a problem hiding this comment.
Yeah, I think the suggestion makes sense.
Artur-Romaniuk
left a comment
There was a problem hiding this comment.
Will apply suggested changes.
43094f9 to
df5ebb7
Compare
|
Rebased on main. Would love to have some feedback. |
newAM
left a comment
There was a problem hiding this comment.
I had some nitpicks with the documentation links but I just did the changes and pushed them since that's easier.
Looks good to me overall. We're going to have unfortunate conflicts with the other PR that touches delays, but that's unavoidable. Will wait for dbrgn's feedback on this too.
|
This PR went stale for a while now. @dbrgn could take a look? |
|
@Artur-Romaniuk because this PR was created on top of the delay branch (#104), I wanted to wait until that branch is ready and merged (and left feedback there) to make review easier. If you want to make PRs easier to review, try to keep them small and focussed. Having a lot of practice with git rebase (especially interactive rebase) helps a lot with that. |
ecf014e to
2705618
Compare
2ec3594 to
09a582a
Compare
That was a fuckup... |
dbrgn
left a comment
There was a problem hiding this comment.
I left a few last comments. The rest is looking great, I think once the comments are addressed this can be merged.
There was a problem hiding this comment.
Yeah, I think the suggestion makes sense.
| /// Optional Data type allows for storage of arbitrary state data in mocks. | ||
| /// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`. |
There was a problem hiding this comment.
| /// Optional Data type allows for storage of arbitrary state data in mocks. | |
| /// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`. | |
| /// The `mock_data` field allows for storage of arbitrary state data in mocks. | |
| /// Mock data can be accessed via appropriate getter/setter methods, i.e. `mock_data()` and `set_mock_data()`. |
| /// | ||
| #[derive(Debug, Clone)] | ||
| pub struct Generic<T: Clone + Debug + PartialEq> { | ||
| pub struct Generic<T: Clone + Debug + PartialEq, Data = ()> { |
There was a problem hiding this comment.
I like the T-prefix convention for type parameters. Can you rename Data to TData?
| //! // Finalizing expectations | ||
| //! io.done(); | ||
| //! | ||
| //! // optional async |
There was a problem hiding this comment.
| //! // optional async | |
| //! // Async is supported as well, if the `embedded-hal-async` feature is enabled |
| pub fn write(expected: Vec<u8>) -> Transaction { | ||
| Transaction { | ||
| expected_mode: Mode::Write, | ||
| expected_data: expected, |
There was a problem hiding this comment.
| pub fn write(expected: Vec<u8>) -> Transaction { | |
| Transaction { | |
| expected_mode: Mode::Write, | |
| expected_data: expected, | |
| pub fn write(expected_data: Vec<u8>) -> Transaction { | |
| Transaction { | |
| expected_mode: Mode::Write, | |
| expected_data, |
| panic!("response longer than read buffer for io::read"); | ||
| } | ||
|
|
||
| let len = std::cmp::min(buffer.len(), transaction.response.len()); |
There was a problem hiding this comment.
Since we already assert above, that the response length can't be larger than the buffer length, can't we just use the response length here?
| let len = std::cmp::min(buffer.len(), transaction.response.len()); | |
| let len = transaction.response.len(); |
| let transaction = self.next().expect("no expectation for io::seek call"); | ||
|
|
||
| if let Mode::Seek(expected_pos) = transaction.expected_mode { | ||
| assert_eq!(expected_pos, pos, "io::seek unexpected mode"); |
There was a problem hiding this comment.
| assert_eq!(expected_pos, pos, "io::seek unexpected mode"); | |
| assert_eq!(expected_pos, pos, "io::seek unexpected pos"); |
| let response_vec = transaction.response; | ||
| self.set_mock_data(Some(response_vec)); |
There was a problem hiding this comment.
Since this variable is only used once, I think it can be inlined.
| let response_vec = transaction.response; | |
| self.set_mock_data(Some(response_vec)); | |
| self.set_mock_data(Some(transaction.response)); |
|
Any chance this gets fixed and merged in a near future? |
|
@Artur-Romaniuk do you have plans to finish this PR, or would you like for someone else to take over? |
|
Would like to bump this issue. Any chance to get embedded-io support added, maybe even async? |
This applies _most_ of the final comments from the review on rust-embedded#101. I phrased one of the changes slightly differently.
This applies _most_ of the final comments from the review on rust-embedded#101. I phrased one of the changes slightly differently.
This applies _most_ of the final comments from the review on rust-embedded#101. I phrased one of the changes slightly differently.
Related to #100