How to find right prototype Combinator, e.g.and_then

For asyn code, when reading existing code, I feel like, ah, it is easy! But when I try to implement my own, I really can't find right prototype for Combinator. e.g.
I'm trying to use thrussh 0.19.6 to implement a simple ssh client.

The document give an example.

 client::connect(
   "127.0.0.1:2222", config, None, self, |connection| { // 1st closure takes 1 parameter. 
      ....
       connection.authenticate_key("pe", key)
          .and_then(|session| {        // 2nd closure takes 1 parameter
            session.channel_open_session()
            .and_then(|(session, channelid)| {  // 3rd Closure takes 2 parameter
              session.data(channelid, None, "Hello, world!")
                 .and_then(|(mut session, _)| {  // 4th Closure takes 2 parameter
                   session.disconnect(Disconnect::ByApplication, "Ciao", "");
                            session 
                        })
                    })
                })
        }).unwrap();

For the 1st Closure, we may find the right prototype from document, the FnOnce signature.

pub fn connect<Addr: ToSocketAddrs, H: Handler, I, E, X: Future<Item = I, Error = E>,
 F: FnOnce(Connection<TcpStream, H>) -> X>(
    addr: Addr, 

But for the 2nd Closure, takes one parameter, session, but authenticate_key returns a Authenticate<R,H>

pub fn authenticate_key(self, user: &str, key: KeyPair) -> Authenticate<R, H>

Then 3rd Closure, takes two parameter, session and channelid, but channel_open_session returns:

pub fn channel_open_session(&mut self) -> Result<ChannelId, Error>

When write my own code, how can I find the right function prototype for the closure? either from document or source code. Thanks. I feel like I couldn't implement any code by myself, only can read others code!

Is there any particular reason as to why you are using such an old version of thrussh? It relies on Tokio v0.1, which was written before async/await was introduced to the language.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.