#io #fifo #queue

queue-file

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

16 stable releases

new 1.4.10 Mar 17, 2023
1.4.8 Feb 14, 2023
1.4.6 Jul 4, 2022
1.3.0 Feb 22, 2022
1.0.2 Jun 27, 2019

#83 in Data structures

Download history 1189/week @ 2022-11-28 2157/week @ 2022-12-05 2276/week @ 2022-12-12 1886/week @ 2022-12-19 430/week @ 2022-12-26 378/week @ 2023-01-02 1169/week @ 2023-01-09 1261/week @ 2023-01-16 1430/week @ 2023-01-23 2135/week @ 2023-01-30 2291/week @ 2023-02-06 1651/week @ 2023-02-13 2312/week @ 2023-02-20 1269/week @ 2023-02-27 1052/week @ 2023-03-06 909/week @ 2023-03-13

5,579 downloads per month
Used in pq-bincode

Apache-2.0

48KB
924 lines

queue-file

Crate API License 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");
}

MSRV

Current MSRV is 1.58.1

License

This project is licensed under the Apache 2.0 license.

Dependencies

~1–1.4MB
~31K SLoC