ninjasource / embedded-websocket

A rust websocket library for embedded systems (no_std)
Apache License 2.0
98 stars 28 forks source link

Add a debug trait impl to the IoError enum. #7

Closed dutchmartin closed 3 years ago

dutchmartin commented 3 years ago

While compiling the current master branch, I got the following error:

error[E0277]: `IoError` doesn't implement `Debug`
  --> src\framer.rs:39:8
   |
39 |     Io(IoError),
   |        ^^^^^^^ `IoError` cannot be formatted using `{:?}`
   |
   = help: the trait `Debug` is not implemented for `IoError`
   = note: add `#[derive(Debug)]` or manually implement `Debug`
   = note: required because of the requirements on the impl of `Debug` for `&IoError`
   = note: required for the cast to the object type `dyn Debug`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

This PR fixes that error by adding a derive macro annotaition.

ninjasource commented 3 years ago

Hi Martijn, thank you for your contribution! I actually fixed that but just hadn't committed my changes. PS, I've been testing the no_std path and found that it was better to pass the stream into each read and write method rather than consuming it when creating the websocket. This is because, when I use it, I need that same network stream somewhere else in my code.

dutchmartin commented 3 years ago

Hi David, thank you for the merge. I am currently trying to use your library in combination with the smoltcp library. When I'll have some success with that, I will try to submit a PR for that.

ninjasource commented 3 years ago

That is great news! I must apologize for the recent API churn. I've been preparing to give a talk and had a lot of changes to make as a result. The latest version 0.8.0 changes the error handling somewhat. I decided to make make one trait called Stream that is generic over the error type. That way whatever implements it can expose complex errors rather than the simple ones I had in IoError above. I have also automatically implemented Stream for TcpStream when linking the standard library. Please let me know what you think of this idea. I'm open to feedback on the API. This repo demonstrates the latest version for no_std: https://github.com/ninjasource/led-display-websocket-demo

dutchmartin commented 3 years ago

Yes, that broke my code while upgrading, but implementing a smoltcp stream is easy, since it is just accepting a stream and implementing the functions defined in your stream trait. I now successfully made a connection. However, the infinite loops in framer are hard to work with in combination with smoltcp. Since that library only updates the socket buffer when it gets polled by a iface.poll() function. So when i call your connect function with a loop, the buffer will be empty or only partly filled, and not be filled until the smoltcp poll function is called (which is not called because the loop in the framer functions will not end).

The solution is to write polling functions, like i did here

ninjasource commented 3 years ago

Thanks, give me a day or two to take a look and think about this. Agreed about the infinite loops. I should yield instead. Perhaps even return a future.