Skip to content

embedded_io_adapters::unblock::Unblock: adapter from embedded_io::{Read, Write} to embedded_io_async::{Read, Write} #652

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

Closed
wants to merge 1 commit into from

Conversation

alsuren
Copy link

@alsuren alsuren commented Mar 6, 2025

Funny story: I burned a bunch of time writing this because I couldn't get embassy's examples/std/src/bin/serial.rs working. I assumed that there was some problem with their serial port adapter or something because it was never returning any data. It turns out my USB UART adapter has a developed broken RX, so this was a bit pointless 😢. I thought I'd share it anyway.

I'm not sure how useful it will be to people:

  • It doesn't currently implement Seek.
  • it's kind-of inefficient.
  • the ergonomics are a bit naff, because it can't just assume embedded_io::ErrorType::Error = std::io::Error (there might be a way around this: I haven't thought about it too hard)

If anything, its main usefulness would probably be to point people towards async_io::Async, and give people a good chuckle at my expense. Feel free to close this PR if you don't think that it is useful. I'm also happy to re-work it, if you think it could be useful but just has the wrong shape.

@alsuren alsuren requested a review from a team as a code owner March 6, 2025 12:17
@alsuren
Copy link
Author

alsuren commented Mar 6, 2025

Turns out this can also be done with blocking::Unblock::new(). I can't get any of these approaches to read from stdin when porting my embassy project to work on desktop though. Probably best to close this until I have something that actually works.

@alsuren alsuren closed this Mar 6, 2025
@dess83-maker
Copy link

when

@alsuren
Copy link
Author

alsuren commented Mar 23, 2025

@dess83-maker when is not a useful comment. Assuming that you are not a spam bot, please expand on your comment. [Edit: it's definitely a spam bot. I have blocked it. If enough people do, maybe GitHub will suspend the account for us?]

For anyone who came here tryng to turn a blocking stdin reader into an async reader in a std+embassy environment:

I think that a cleaner approach is to just write a blocking parser and then spawn a thread to dump the messages on a channel. See this code as an example:

https://github.com/hoverkite/hoverkite/pull/245/files#diff-2009529c3fa33e0843368f5f842d3ca1845ba36c7aedcd6751d3fe7121742730R124

It means that you end up with an awkward mix of blocking and async parsers dotted around your codebase, but I think it's fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants