This is probably the dumbest question in the history of Rust, but I gotta ask..
If you look at this code ... how do you determine where send() comes from? I'm writing my own tokio-utilEncoder, and realized when I wanted to actually use it that send() doesn't exist in Framed, and while browsing the docs I have not been able to find it.
This is something that happens from time to time, and what I end up doing is just copying use-lines from working examples and once it starts working I know what I need and remove the rest. Learning how to do this properly is long overdue..
(Not asking about how to do this with snazzy plugins in Visual Studio Code or similar, I want to know how to do it "manually" by just reading the docs).
This one is particularly tricky to find if you are not familiar with the futures crate.
First note that Framed implements Sink which has a Sink::start_send method. (Wait, that sounds familiar!). Note that all of futures' traits have an *Ext version that is contains some ergonomic methods. In this case SinkExt, which has the desired SinkExt::send
If you try to compile that code without importing the correct trait, the error message includes this note:
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
44 | use futures_util::sink::SinkExt;
|
I don't think it's always practical to do this "just by reading the docs" because the docs just don't have a way to see a complete listing of all methods you can call on a type. Specifically, they don't list methods from "indirect" generic impls like the one for SinkExt.
error[E0599]: no method named `send` found for struct `tokio_util::codec::framed::Framed<tokio::net::unix::stream::UnixStream, ProtCodec>` in the current scope
--> distcontstored/src/main.rs:481:15
|
481 | input.send(&ret).await;
| ^^^^ method not found in `tokio_util::codec::framed::Framed<tokio::net::unix::stream::UnixStream, ProtCodec>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0599`.
error: could not compile `distcontstored`.
To learn more, run the command again with --verbose.
I assume one has to have the proper crates pulled in for that to work.
Interesting insight: You kind of have to have quite a bit of knowledge about "neighbor" crates, since the docs won't necessarily help you. Also, no one can yell "RTFM!" at you, for the same reason.
There is work on linking better to the extension traits — you can already see it on the core Tokio types such as TcpStream, but the tokio-util crate has not yet gotten that treatment.