Closed badger-io closed 1 year ago
That's correct. Streams are similar to iterators. Iterator
trait in Rust returns Option<Self::Item>
, not the Result<Self::Item>
. Same with the Stream
. The type when reading from the stream would be Option<Result<...>>
, not the Result<Option<..>>
!
Your tcp_read
function is written in a generic way and does not say anything about the type of the stream except that it implements the StreamExt
. So you either need to pass the actual type to the function, or add additional requirements to the function by stating the expectations of the stream to implement the traits that you intend to use, i.e. in your case you need to add a requirement to the function definition that you want the stream to implement TryStreamExt.
Hey, I'm modifying this repo https://github.com/Darksonn/telnet-chat to use websockets (just for fun) and I've run into an issue with types/traits.
I've modified the
client_loop
function to callaccept_async
to start the handshake. I then split the stream and pass the parts to two separate functions:So far so good. The problem comes when trying to consume the stream in the read function. I've tried different methods from the example code but always get a trait error related to
try
.Using a while loop with
?
Gives error
Using
try_filter
I get the following error
What am I missing? I get the same errors if I try to consume the stream directly in the
client_loop
function.For reference:
Cargo.toml