Crate fifo [] [src]

A first-in-first-out bytes ring-buffer like kfifo in Linux.

Example

use std::io::prelude::*;
use fifo::{fifo, Sender, Receiver};

let (mut sender, mut receiver): (Sender, Receiver) = fifo(128);

let bytes_to_write = [0 as u8; 512];
assert_eq!(sender.write(&bytes_to_write).unwrap(), 128);

let mut bytes_to_read = [1 as u8; 512];
assert_eq!(receiver.read(&mut bytes_to_read).unwrap(), 128);

assert_eq!(bytes_to_write[0..128], bytes_to_read[0..128]);

assert!(sender.as_ref().unread() >= 0);

Modules

splice

Zero-copy interface for Sender and Receiver, in splice style in Linux. When you want to write bytes into the ring-buffer from a Read, or read bytes from this into a Write, you can use SpliceRead and SpliceWrite.

Structs

Receiver

The fifo receiver. It's Send but !Send.

Sender

The fifo sender. It's Send but !Send.

Enums

WouldBlock

What can we do when operations on Sender or Receiver would block.

Functions

fifo

Construct the fifo with capacity as size.next_power_of_two(), and return the Sender and Receiver pair connected with that.