Skip to main content

Crate bus_contract_crossing

Crate bus_contract_crossing 

Expand description

§bus-contract-crossing

The crossing contract of bus-contract: what may cross a process boundary and what it means when it does: the Relay capability, on top of the journal, with codecs, origins, authorities and asks answered across processes.

bus-contract is a small core (points, order, alter and collect, requests, local listeners, introspection) plus optional capabilities. Each capability is its own contract, published as its own crate and versioned on its own, so a change to one does not break the users of the others.

It depends on bus-contract-journal: a bus that offers Relay offers Journal, and this crate re-exports BusJournal, Journal, JournalEntry and Since.

§Use

use std::sync::Arc;
use bus_contract_crossing::BusCrossing;

/// Whether the bus can relay to another process.
fn has_crossing(bus: &Arc<dyn bus_contract::Bus>) -> bool {
    bus.relay().is_some()
}
  • BusCrossing gives bus.relay() on any bus: dyn Bus, Arc<dyn Bus> or a concrete one. It returns None when the bus does not offer the capability.
  • The contract’s items live here: Relay, Codec, Relayed, RelayedRequest, Origin, Answer, Authority, Crossing, Cursor, IngestError, Lost, Resumed, the relayed messages, far_listener, ask_run, the CONTRACT (which requires the journal one), the relayable(&CODEC), relayable_event::<P>() and relayable_request::<P>() facets with codec, and check / applied for implementations. The journal items it sits on are re-exported.

§Status: owns its contract since 0.2

Since 0.2, with bus-contract 0.5, the items above are defined here, not in the core. The core names no capability: it keeps the typed lookup (Bus::capability), the Contract and Facet types, and offers. BusCrossing reaches the capability through that lookup only.

Upgrading from 0.1 and bus-contract 0.4: import the items from bus_contract_crossing and add use bus_contract_crossing::BusCrossing; where bus.relay() is called. Every rename is in MIGRATION-0.5.md.

§Guarantees

What a bus offering this capability guarantees, and what it does not, property by property with stable ids, is the crossing section of GUARANTEES.md. Each property names the bus-kernel conformance check that proves it.

§Versions

Released on its own, with its own CHANGELOG. Needs bus-contract 1. See RELEASING.md for the repository’s crates and their publish order.

§License

MIT or Apache-2.0, at your option.

Structs§

Codec
How a relayable point’s input is written and read (Relayed), and a relayable request’s value (RelayedRequest), its types erased, for a contract table (relayable). Two codecs are equal when they are for the same point.
Crossing
What an authority of a bus is shown of something crossing in (Relay::add_authority), before anything is decoded or recorded.
Cursor
Where a reader of a relay stands: the journal run it read and the last number it took.
JournalEntry
One event of a journal: what happened, its number, what caused it.
Origin
Who sent what crosses a process boundary: the far side of a link, as the receiving side knows it.
RelayedAnswer
The answer to one ask (Relay::answer), naming it.
RelayedAsk
A request asked of another process (Relay::answer): its input and the value so far, as text, with the time the asker waits.
RelayedEntry
An event as it crosses a process (Relay): its input as text.
Resumed
What a relay read found (Relay::resume).
Since
What a read of a journal after a number found (Journal::since).

Enums§

Answer
How an ask was answered (RelayedAnswer::answer).
IngestError
Why an entry relayed in was not taken (Relay::ingest).
Lost
Why a reader of a relay missed entries (Resumed::lost).

Constants§

CONTRACT
The crossing contract: a bus offers it by answering for dyn Relay in Bus::capability, and offers the journal contract too. A relayable point says so with the relayable facet, which needs this contract.
JOURNALED
The facet of a journaled event point: its events go through the bus’s journal, published with a number and delivered to the listeners in journal order after the publisher has moved on (PointDecl::of::<P>(…).facets(&[JOURNALED]), or PointSpec::new(…).facet(JOURNALED)). Only an event point is journaled (check).

Traits§

BusCrossing
Reaches the Relay capability of any bus: bus.relay().
BusJournal
Reaches the Journal capability of any bus: bus.journal().
Journal
A capability of a bus (BusJournal::journal): events kept in order with a number, read again from a number, and delivered to their point’s listeners after the publisher has moved on.
Relay
A capability of a bus (BusCrossing::relay), on top of its Journal: what crosses a process boundary. The events of relayable points served to another process from a cursor and taken in from one as if published here; the asks of relayable request points answered here for another process.
Relayed
An event point whose input can cross a process: written as text by one bus, read back by another (Relay).
RelayedRequest
A request point that can be answered by another process (Relay::answer): its value, as well as its input, written as text and read back.

Functions§

applied
The spec as a bus that implements crossing applies it: a relayable event point is journaled (JOURNALED added), a relayable request is fail-closed.
ask_run
This process’s run, for the asks it sends (RelayedAsk::run): fixed while the process runs, another one after a restart.
check
What the crossing contract refuses in a declaration, for an implementation’s declare_point (Refused::Contract): a relayable point with another point’s codec, an alter or collect point, a request whose codec writes no value.
codec
The codec of a relayable point, from its facets (PointSpec::facets, PointInfo::facets); None when it is not relayable.
far_listener
The listener that stands, on the asking side, for the far side of a relayable request point: register it on the point here (with the point’s deadline and threaded, so the emit stops waiting at the deadline), and the far side’s listeners take their turn in this side’s order, at its place.
is_journaled
Whether facets (PointSpec::facets, PointInfo::facets) mark the point journaled.
relayable
The facet of a relayable point, carrying its codec: the point crosses processes (Relay):
relayable_event
The relayable facet of the event point P, its codec Codec::of::<P>(): usable in a const table and at run time alike (.facets(&[relayable_event::<DocChanged>()]), PointSpec::new(…).facet(relayable_event::<DocChanged>())).
relayable_request
The relayable facet of the request point P, its codec Codec::request::<P>(): usable in a const table and at run time alike.

Type Aliases§

Authority
Decides whether what crosses in may be taken (Relay::add_authority): Err(reason) refuses it.
DecodeFn
Reads an event’s input back from text, its type erased.
DecodeValueFn
Reads a request’s value back from text into a value of the point’s type, its type erased, replacing it.
EncodeFn
Writes an event’s input as text, its type erased; None when the input is not of the point’s type.
EncodeValueFn
Writes a request’s value as text, its type erased; None when the value is not of the point’s type.