#io #fifo #queue

queue-file

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

12 stable releases

1.4.6 Jul 4, 2022
1.4.5 Jun 1, 2022
1.4.3 May 30, 2022
1.4.0 Apr 26, 2022
1.0.2 Jun 27, 2019

#68 in Data structures

Download history 1394/week @ 2022-06-12 1069/week @ 2022-06-19 1230/week @ 2022-06-26 1158/week @ 2022-07-03 826/week @ 2022-07-10 1031/week @ 2022-07-17 726/week @ 2022-07-24 1470/week @ 2022-07-31 1010/week @ 2022-08-07 1030/week @ 2022-08-14 1284/week @ 2022-08-21 2029/week @ 2022-08-28 1520/week @ 2022-09-04 980/week @ 2022-09-11 1846/week @ 2022-09-18 1365/week @ 2022-09-25

5,716 downloads per month
Used in pq-bincode

Apache-2.0

45KB
833 lines

queue-file

Crate API License Build Status Windows Build Status

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

Addition and removal of an element from the queue 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"

Example

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.5–1MB
~19K SLoC