bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Provide try_get_* methods for `Buf`

Open caelunshun opened this issue 6 years ago • 4 comments

Add try_get_* methods on Buf which return error values rather than panicking when there are not enough remaining bytes. This allows for cleaner networking code when dealing with variable-length packets.

Resolves #254.

caelunshun avatar Jul 30 '19 16:07 caelunshun

I think I'm fine with this. In the next breaking release, all of these fns will be moved to an ext trait anyway.

I wonder what others think.

cc @seanmonstar

carllerche avatar Jul 30 '19 17:07 carllerche

This would be great to have IMO

sfackler avatar Nov 21 '19 01:11 sfackler

Can we get this PR updated?

carllerche avatar Nov 21 '19 02:11 carllerche

Working on the h3 we have workaround traits for not panicking in the webserver if the incoming frame was not long enough or malformed. It would be great to have this kind of thing in Bytes directly

ten3roberts avatar Apr 04 '23 19:04 ten3roberts