-
Notifications
You must be signed in to change notification settings - Fork 25
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
IO implementation for embedded-io #101
base: main
Are you sure you want to change the base?
Conversation
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.
Looks good, thanks for adding the feature, just some structural changes I would make.
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.
This should go under src/io.rs
since embedded-io
is versioned independently of embedded-hal
.
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.
@dbrgn If you could give your opinion on this?
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.
Yeah, I think the suggestion makes sense.
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.
Will apply suggested changes.
43094f9
to
df5ebb7
Compare
Rebased on main. Would love to have some feedback. |
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 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... |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//! // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
Related to #100