Skip to content

How to properly use BytesMut with UnixDatagram recv/recv_from? #2741

Answered by Darksonn
xonatius asked this question in General
Discussion options

You must be logged in to vote

This is generally a problem with all IO sources. If you don't want to zero the memory first, the correct way to do it is to call BufMut::bytes_mut to obtain a reference into the extra capacity, then unsafely cast it to an &mut [u8], which you can then give to the datagram. You can then call BufMut::advance_mut after you know how much data was written into the slice.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@xonatius
Comment options

@Darksonn
Comment options

@xonatius
Comment options

@Darksonn
Comment options

Answer selected by xonatius
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants