How to find particular method in docs

Given this example from the tokio-serde docs:

How do I find where the highlighted .send method is coming from?

  • serialized is a SymmetricallyFramed (docs.rs/tokio-serde/latest/tokio_serde/type.SymmetricallyFramed.html)
  • which is an type definition for Framed (docs.rs/tokio-serde/latest/tokio_serde/struct.Framed.html)
  • which doesn't seem to have a 'send' method (tokio_serde::Framed - Rust)
  • and doesn't seem to have a 'send' method in its implemented traits (docs.rs/tokio-serde/latest/tokio_serde/struct.Framed.html#trait-implementations)

I guess I'm missing something basic or slightly less basic. I've written a small amount of Rust but have limited experience with in-depth libraries and navigating around these things.

Thanks in advance! Sorry I can only put two links in a post as a new member.

Yeah, this is an annoying example.
The send method comes from the futures-util crate, in the SinkExt trait. I am guessing it is re-exported in the futures crate's prelude. There is a implementation of SinkExt for any type that implements Sink. And Framed implements Sink.
Such transitive impls don't show up in docs. I dug it up with rust-analyzer.

2 Likes

Well, I feel like less of an idiot now :slight_smile: I will try to get more information through rust analyzer in future.

Check it out with the following steps:

  1. Framed implements futures_sink::Sink trait
  2. futures_util crate reexports the futures_sink::Sink trait in futures_util::sink mod and defines a subtrait SinkExt as well as a blanket impl to have all types implemented with Sink also implements SinkExt there
  3. Finally futures crate reexports Sink and SinkExt in futures::prelude which is imported by the end user

tokio-serde only needs futures_sink::Sink trait for Framed, and the user can gain extra functionality (like send method) from SinkExt trait through futures_util or futures crate.

1 Like

Foreign traits are only usable if they are explicitly imported, so if you can't find the method in the inherent impl, look at the crates/traits imported by the current module.

2 Likes