#io #fifo #queue

queue-file

queue-file is a lightning-fast, transactional, file-based FIFO

4 stable releases

✓ Uses Rust 2018 edition

1.1.0 Jan 17, 2020
1.0.2 Jun 27, 2019
1.0.1 Jun 24, 2019

#230 in Data structures

Download history 10/week @ 2020-03-14 18/week @ 2020-03-21 27/week @ 2020-03-28 14/week @ 2020-04-04 78/week @ 2020-04-11 46/week @ 2020-04-18 35/week @ 2020-04-25 41/week @ 2020-05-02 45/week @ 2020-05-09 34/week @ 2020-05-16 33/week @ 2020-05-23 45/week @ 2020-05-30 13/week @ 2020-06-06 25/week @ 2020-06-13 24/week @ 2020-06-20 62/week @ 2020-06-27

102 downloads per month

Apache-2.0

36KB
722 lines

queue-file

Crate API License Build Status Windows Build Status

queue-file is a lightning-fast, transactional, file-based FIFO.

Addition and removal from an instance is an O(1) operation and is atomic. Writes are synchronous by default; data will be written to disk before an operation returns.

queue-file crate is a feature complete and binary compatible port of QueueFile class from Tape2 by Square, Inc. Check the original project here.

Documentation

Usage

To use queue-file, first add this to your Cargo.toml:

[dependencies]
queue-file = "1.0"

Then, add this to your crate root:

extern crate queue_file;

Example

extern crate queue_file;

use queue_file::QueueFile;

fn main() {
    let mut qf = QueueFile::open("example.qf")
        .expect("cannot open queue file");

    qf.add("ELEMENT #1".as_bytes()).expect("add failed");
    qf.add("ELEMENT #2".as_bytes()).expect("add failed");
    qf.add("ELEMENT #3".as_bytes()).expect("add failed");

    qf.remove().expect("remove failed");

    for (index, elem) in qf.iter().enumerate() {
        println!(
            "{}: {} bytes -> {}",
            index,
            elem.len(),
            std::str::from_utf8(&elem).unwrap_or("<invalid>")
        );
    }

    qf.clear().expect("clear failed");
}

License

This project is licensed under the Apache 2.0 license.

Dependencies

~0.6–1MB
~22K SLoC