UdpSocket.recv() using uninitialized Vec #5563
Labels
A-tokio
Area: The main tokio crate
C-feature-request
Category: A feature request.
M-net
Module: tokio/net
Is your feature request related to a problem? Please describe.
As today
UdpSocket.recv()
andUdpSocket.recv_from()
require aVec<u8> with length > 0
.This prevents users to use a
Vec<u8>
created withVec::with_capacity()
for skipping the vec initialization; the methods always returnsOK(0)
.As workaround try_recv_buf_from and try_recv_buf are available but they increase the code complexity.
Describe the solution you'd like
I've considered the following alternatives:
recv_buf
andrecv_buf_from
: they will work with buf havinglength=0
without the complication of try variants.Describe alternatives you've considered
&mut [u8]
to&mut BufMut
. I'm not sure if that's an acceptable solutionAdditional context
As bonus point, it would be nice to improve methods documentations to underline the different behavior of the current methods: as today, the difference is only shown in the code snippets (not in the description).
The text was updated successfully, but these errors were encountered: