Struct asyncio::StreamBuf
[−]
[src]
pub struct StreamBuf { /* fields omitted */ }
Automatically resizing buffer.
Methods
impl StreamBuf
[src]
fn new() -> StreamBuf
Returns a new StreamBuf
.
Equivalent to with_max_len(usize::max_len())
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::new();
fn with_max_len(max: usize) -> StreamBuf
Returns a new StreamBuf
with the max length of the allocatable size.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::with_max_len(1024);
fn capacity(&self) -> usize
Returns an allocated size of the buffer.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::new(); assert_eq!(sbuf.capacity(), 0);
fn clear(&mut self)
Clears the buffer, removing all values.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::from(vec![1,2,3]); sbuf.clear(); assert_eq!(sbuf.is_empty(), true);
fn consume(&mut self, len: usize)
Remove characters from the input sequence.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::from(vec![1,2,3]); assert_eq!(sbuf.len(), 3); sbuf.consume(3); assert_eq!(sbuf.len(), 0);
fn commit(&mut self, len: usize)
Move characters from the output sequence to the input sequence.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::new(); let _ = sbuf.prepare(256); assert_eq!(sbuf.len(), 0); sbuf.commit(3); assert_eq!(sbuf.len(), 3);
fn is_empty(&self) -> bool
Returns true
if the empty buffer.
Examples
use asyncio::StreamBuf; let sbuf = StreamBuf::new(); assert!(sbuf.is_empty());
fn len(&self) -> usize
Returns a length of the input sequence.
Examples
use asyncio::StreamBuf; let sbuf = StreamBuf::from(vec![1,2,3]); assert_eq!(sbuf.len(), 3);
fn max_len(&self) -> usize
Returns a maximum length of the StreamBuf
.
Examples
use asyncio::StreamBuf; let sbuf = StreamBuf::new(); assert_eq!(sbuf.max_len(), usize::max_value());
fn prepare(&mut self, len: usize) -> Result<&mut [u8]>
Returns a &mut [u8]
that represents a output sequence.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::with_max_len(8); assert_eq!(sbuf.prepare(5).unwrap().len(), 5); sbuf.commit(5); assert_eq!(sbuf.prepare(5).unwrap().len(), 3);
fn prepare_exact(&mut self, len: usize) -> Result<&mut [u8]>
Returns a &mut [u8]
that represents a output sequence.
Examples
use asyncio::StreamBuf; let mut sbuf = StreamBuf::with_max_len(8); assert_eq!(sbuf.prepare_exact(5).unwrap().len(), 5); sbuf.commit(5); assert!(sbuf.prepare_exact(5).is_err());
fn as_slice(&self) -> &[u8]
Returns a &[u8]
that represents the input sequence.
fn as_mut_slice(&mut self) -> &mut [u8]
Returns a &mut [u8]
that represents the input sequence.
Trait Implementations
impl Clone for StreamBuf
[src]
fn clone(&self) -> StreamBuf
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for StreamBuf
[src]
impl Default for StreamBuf
[src]
impl AsRef<StreamBuf> for StreamBuf
[src]
impl AsMut<StreamBuf> for StreamBuf
[src]
impl AsRef<[u8]> for StreamBuf
[src]
impl AsMut<[u8]> for StreamBuf
[src]
impl From<Vec<u8>> for StreamBuf
[src]
impl From<CString> for StreamBuf
[src]
impl<'a> From<&'a [u8]> for StreamBuf
[src]
impl<'a> From<&'a str> for StreamBuf
[src]
impl Read for StreamBuf
[src]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0
Read all bytes until EOF in this source, placing them into buf
. Read more
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0
Read the exact number of bytes required to fill buf
. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0
Creates a "by reference" adaptor for this instance of Read
. Read more
fn bytes(self) -> Bytes<Self>
1.0.0
Transforms this Read
instance to an Iterator
over its bytes. Read more
fn chars(self) -> Chars<Self>
io
): the semantics of a partial read/write of where errors happen is currently unclear and may change
Transforms this Read
instance to an Iterator
over char
s. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where R: Read
1.0.0
Creates an adaptor which will chain this stream with another. Read more
fn take(self, limit: u64) -> Take<Self>
1.0.0
Creates an adaptor which will read at most limit
bytes from it. Read more
impl Write for StreamBuf
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0
Creates a "by reference" adaptor for this instance of Write
. Read more