Reference / Channels API for Rust

Channels API for Rust

Every public type, trait and function of the Channels engine in tinystore::channels and tinystore::aio::channels, generated from its source. The Channels guide explains how to use them, and the Bun and Node, Python and Go pages list the same API.

Store

rust
impl Store

Store.channel

rust
pub fn channel<T>(&self, name: &str) -> ChannelBuilder<T>

A channel of messages of one type: every subscriber listening when a message is published receives it, and nobody after.

aio::Store

rust
impl aio::Store

aio::Store.channel

rust
pub fn channel<T>(&self, name: &str) -> ChannelBuilder<T>

A channel of messages of one type, as crate::Store::channel: every listener when a message is published receives it, and nobody after.

ChannelBuilder

rust
pub struct ChannelBuilder<T> { /* private fields */ }

A channel being opened.

ChannelBuilder.open

rust
pub fn open(self) -> Result<Channel<T>>

Channel

rust
pub struct Channel<T> { /* private fields */ }

A channel, or one of its branches.

Channel.under

rust
pub fn under(&self, owner: impl Key) -> Channel<T>

The branch of owner under this one: whose messages these are.

Channel.publish

rust
pub fn publish(&self, value: &T) -> Result<()>

Hands value to every subscriber of this branch, and of the branches above it listened to recursive, that listens now. It answers once the store has the message, not once anyone handled it.

Channel.subscribers

rust
pub fn subscribers(&self) -> Result<usize>

How many subscriptions a message published on this branch now would reach: this branch's own, and the recursive ones of it and of every branch above it, in every process that reaches the store. Without under it counts the root's, not every branch's.

Channel.recursive

rust
pub fn recursive(&self) -> Subscribing<T>

A subscription that takes every branch below this one too.

Channel.on_missed

rust
pub fn on_missed(&self, missed: impl FnMut(Missed) + Send + 'static) -> Subscribing<T>

A subscription told what it missed: by default the store's log says it, once a minute at most.

Channel.on_error

rust
pub fn on_error(&self, failed: impl FnMut(Error) + Send + 'static) -> Subscribing<T>

A subscription told what failed: a handler that panicked, a message that does not read as the channel's type.

Channel.subscribe

rust
pub fn subscribe(&self, handler: impl FnMut(Message<T>) + Send + 'static) -> Result<Subscription>

Calls handler with each message published from now on, one at a time and in order, on a thread of the store's.

Channel.each

rust
pub fn each(&self) -> Result<Each<T>>

The messages published from now on, on the caller's thread.

Message

rust
pub struct Message<T> {
    pub value: T,
    pub branch: Vec<String>,
}

A message as a subscriber receives it: what was published, and the branch it was published under.

Missed

rust
pub struct Missed {
    pub count: u64,
}

Messages a subscriber lost: it fell so far behind that its branch's log let them go.

Subscribing

rust
pub struct Subscribing<T> { /* private fields */ }

A subscription being made: whether it takes the branches below, and what it is told when it misses messages or a call fails.

Subscribing.recursive

rust
pub fn recursive(self) -> Self

Subscribing.on_missed

rust
pub fn on_missed(self, missed: impl FnMut(Missed) + Send + 'static) -> Self

Subscribing.on_error

rust
pub fn on_error(self, failed: impl FnMut(Error) + Send + 'static) -> Self

Subscribing.subscribe

rust
pub fn subscribe(self, handler: impl FnMut(Message<T>) + Send + 'static) -> Result<Subscription>

Subscribing.each

rust
pub fn each(self) -> Result<Each<T>>

The messages as an iterator on the caller's thread. A message that does not read is an Err item there, so on_error has nothing to say.

Subscription

rust
pub struct Subscription { /* private fields */ }

A subscription whose handler runs on the store's threads. Dropped, it goes on listening, as a queue's worker goes on working: stop ends it, and so does the store's close.

Subscription.stop

rust
pub fn stop(&self)

No call starts after it, and it returns once the running call ended; from inside the subscription's own handler, at once.

Each

rust
pub struct Each<T> { /* private fields */ }

The messages published from now on, as an iterator on the caller's thread: next waits for the next, and answers None once stopped or once the store closed. A message that does not read as the channel's type is an Err item, and the next follows.

Each.stopper

rust
pub fn stopper(&self) -> Stopper

What stops the loop from another thread: its next answers None.

Stopper

rust
pub struct Stopper(_)

Stops an Each from another thread.

Stopper.stop

rust
pub fn stop(&self)

TxChannel

rust
pub struct TxChannel<'t, T> { /* private fields */ }

A channel inside a transaction: its messages wait for the commit, and a rollback hands none over.

TxChannel.under

rust
pub fn under(&self, owner: impl Key) -> TxChannel<'t, T>

The branch of owner under this one, in the same transaction.

TxChannel.publish

rust
pub fn publish(&self, value: &T) -> Result<()>

Hands value over once the transaction commits, in the order its file commits; nothing when it rolls back. A store that dies between the commit and the handing over loses it: an event that must go out with its rows is a queue in the same database.

aio::channels::ChannelBuilder

rust
pub struct ChannelBuilder<T> { /* private fields */ }

A channel being opened, as crate::channels::ChannelBuilder.

aio::channels::ChannelBuilder.open

rust
pub fn open(self) -> Result<Channel<T>>

Opens the channel: a plain call, in memory.

aio::channels::Channel

rust
pub struct Channel<T> { /* private fields */ }

A channel, or one of its branches, as crate::channels::Channel.

aio::channels::Channel.under

rust
pub fn under(&self, owner: impl Key) -> Channel<T>

The branch of owner under this one: whose messages these are.

aio::channels::Channel.publish

rust
pub fn publish(&self, value: &T) -> Result<()>

Hands value to every listener of this branch, and of the branches above it listened to recursive, as crate::channels::Channel::publish. A plain call: the message is put in memory, the oldest shed rather than waited for, and nothing is awaited.

aio::channels::Channel.subscribers

rust
pub fn subscribers(&self) -> Result<usize>

How many subscriptions a message published on this branch now would reach, as crate::channels::Channel::subscribers. A plain call: it counts what the store holds in memory, and nothing is awaited.

aio::channels::Channel.recursive

rust
pub fn recursive(&self) -> Subscribing<T>

A loop that takes every branch below this one too.

aio::channels::Channel.on_missed

rust
pub fn on_missed(&self, missed: impl FnMut(Missed) + Send + 'static) -> Subscribing<T>

A loop told what it missed, before its next message: by default the store's log says it, once a minute at most. missed runs on the thread that polls the stream.

aio::channels::Channel.each

rust
pub fn each(&self) -> Result<Each<T>>

The messages published from now on, as a Stream: it listens from this call, polled yet or not, so a program that must hear its own message makes it first. A message that does not read as the channel's type is an Err item, and the next follows; the stream ends once its stopper stops it or once the store closed.

aio::channels::Channel.blocking

rust
pub fn blocking(&self) -> &Channel<T>

The same channel, for its blocking calls, subscribe among them.

aio::channels::Subscribing

rust
pub struct Subscribing<T> { /* private fields */ }

A loop being made: whether it takes the branches below, and what it is told when it misses messages.

aio::channels::Subscribing.recursive

rust
pub fn recursive(self) -> Self

aio::channels::Subscribing.on_missed

rust
pub fn on_missed(self, missed: impl FnMut(Missed) + Send + 'static) -> Self

aio::channels::Subscribing.each

rust
pub fn each(self) -> Result<Each<T>>

As Channel::each.

aio::channels::Each

rust
pub struct Each<T> { /* private fields */ }

The messages published from now on, as a Stream: woken by each publish, it takes up to 64 messages a poll from its log, which keeps what it has not read, 1,024 messages or 4 MiB, and tells on_missed what it lost past them. It parks no thread. Dropped, it stops listening.

aio::channels::Each.stopper

rust
pub fn stopper(&self) -> Stopper

What stops the stream from another task or thread: it ends, None.

Generated from the source Updated 19 November 2026

esc
↑↓ navigate ↵ open ⇥ filter 0 results