Skip to content
Snippets Groups Projects
Commit e4fd3924 authored by Andrew Hobden's avatar Andrew Hobden
Browse files

Add Read and Write to RingBuf

parent 74a59c66
No related branches found
No related tags found
No related merge requests found
use super::{Buf, MutBuf};
use std::{cmp, fmt, mem, ptr, slice};
use std::rt::heap;
use std::io;
/// Buf backed by a continous chunk of memory. Maintains a read cursor and a
/// write cursor. When reads and writes reach the end of the allocated buffer,
......@@ -184,4 +185,28 @@ impl MutBuf for RingBuf {
}
}
impl io::Read for RingBuf {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if !MutBuf::has_remaining(self) {
return Ok(0);
}
Ok(self.read_slice(buf))
}
}
impl io::Write for RingBuf {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if !Buf::has_remaining(self) {
return Ok(0);
}
Ok(self.write_slice(buf))
}
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}
unsafe impl Send for RingBuf { }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment