Recently I wrote article how SSH port forwarding works and how to implement it in Rust:
https://dev.to/bbkr/ssh-port-forwarding-from-within-rust-code-5an
I hope it answers your question.