Since this often matters when implementing protocols, there is research about session types and verification. Here is a Rust library for session types: https://github.com/Munksgaard/session-types
I believe both have some overlap.
I believe both have some overlap.