`tokio` and `bincode`: reading from a socket

⚓ rust    📅 2025-06-03    👤 surdeus    👁️ 1      

surdeus

I have a UnixStream socket in an application using tokio. I also have some structs that use bincode's Encode and Decode traits. I know that bincode handles the length of variable-length fields (like Strings), but I don't think the sockets do. If I don't read a full struct from the socket, I doubt it'll decode() properly. How do I read from a tokio socket, such that I can be sure that I've read a full struct?

Edit:
Does bincode maybe have a way to automatically decode() directly from a tokio socket?

6 posts - 4 participants

Read full topic

🏷️ rust_feed