Skip to main content

Queue

Struct Queue 

Source
pub struct Queue { /* private fields */ }
Expand description

A persisted, low-latency message queue.

Uses memory-mapped files organized into cycle files based on time.

§Thread Safety

  • One Writer per thread
  • Multiple Readers can read concurrently
  • The queue itself is Send + Sync

§Example

use khata_rs::Queue;

let queue = Queue::new("/tmp/my-queue").build()?;

let mut writer = queue.writer()?;
writer.write(b"Hello, World!")?;

Implementations§

Source§

impl Queue

Source

pub fn new(path: impl Into<PathBuf>) -> QueueBuilder

Creates a new builder for a queue at the given path.

Source

pub fn writer(&self) -> Result<Writer<'_>>

Creates a writer for appending messages.

§Errors

Returns Error::ReadOnly if opened in read-only mode.

Source

pub fn reader(&self) -> Result<Reader<'_>>

Creates a reader for consuming messages.

Source

pub fn path(&self) -> &Path

Returns the queue directory path.

Source

pub fn roll_cycle(&self) -> &dyn RollCycle

Returns the roll cycle configuration.

Source

pub fn block_size(&self) -> usize

Returns the block size.

Source

pub fn epoch(&self) -> u64

Returns the epoch offset.

Source

pub fn is_read_only(&self) -> bool

Returns whether the queue is read-only.

Source

pub fn checksums_enabled(&self) -> bool

Returns whether CRC-16 checksums are enabled.

Source

pub fn index_spacing(&self) -> u32

Returns the index spacing.

Source

pub fn index_count(&self) -> u32

Returns the index count per array.

Source

pub fn first_cycle(&self) -> Option<i32>

Returns the first (oldest) cycle, if any.

Source

pub fn last_cycle(&self) -> Option<i32>

Returns the last (newest) cycle, if any.

Source

pub fn current_cycle(&self) -> i32

Returns the current cycle based on current time.

Source

pub fn filename_for_cycle(&self, cycle: i32) -> String

Generates the filename for a given cycle.

Auto Trait Implementations§

§

impl !Freeze for Queue

§

impl !RefUnwindSafe for Queue

§

impl Send for Queue

§

impl Sync for Queue

§

impl Unpin for Queue

§

impl !UnwindSafe for Queue

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.