CircBuf
An implementation of a growable circular buffer of bytes. The CircBuf struct
manages a buffer of bytes allocated on the heap. The buffer can be grown when needed
and can return slices into its internal buffer that can be used for both normal IO
(read and write) as well as vector IO (readv and writev).
bytes support
If the bytes feature flag is enabled, then the bytes
crate will be added as a dependency and the Buf and BufMut traits implemented for
CircBuf. The optional vectored read/write functions are implemented, allowing you to use
the CircBuf for efficient vectored IO operations with libraries such as tokio. See
for example the read_buf
and write_buf
methods, which can accept a CircBuf when the bytes feature flag is enabled.
Example
Below is a simple example of a server which makes use of a CircBuf to read messages
from a client. It uses the vecio crate to call readv on the socket. Messages are seperated by a
vertical bar | and the server returns to the client the number of bytes in each message it receives.
extern crate vecio;
extern crate circbuf;
use thread;
use ;
use Write;
use Rawv;
use CircBuf;