Skip to content

Where to get num_bytes_read from, when using new AsyncRead::poll_read? #2990

Answered by Darksonn
Urhengulas asked this question in Q&A
Discussion options

You must be logged in to vote

Since you created the ReadBuf, you know that it starts with filled() empty. Thus, the number of bytes can be obtained with read_buf.filled().len() after calling poll_read. You may enjoy this snippet:

let n = {
let mut buf = ReadBuf::uninit(buf.bytes_mut());
ready!(read.poll_read(cx, &mut buf)?);
buf.filled().len()
};

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Urhengulas
Comment options

@Darksonn
Comment options

@Urhengulas
Comment options

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