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()
}BusCrossinggivesbus.relay()on any bus:dyn Bus,Arc<dyn Bus>or a concrete one. It returnsNonewhen 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, theCONTRACT(which requires the journal one), therelayable(&CODEC),relayable_event::<P>()andrelayable_request::<P>()facets withcodec, andcheck/appliedfor 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.
- Journal
Entry - 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.
- Relayed
Answer - The answer to one ask (
Relay::answer), naming it. - Relayed
Ask - A request asked of another process (
Relay::answer): its input and the value so far, as text, with the time the asker waits. - Relayed
Entry - 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). - Ingest
Error - 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 RelayinBus::capability, and offers the journal contract too. A relayable point says so with therelayablefacet, 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]), orPointSpec::new(…).facet(JOURNALED)). Only an event point is journaled (check).
Traits§
- BusCrossing
- Reaches the
Relaycapability of any bus:bus.relay(). - BusJournal
- Reaches the
Journalcapability 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 itsJournal: 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). - Relayed
Request - 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 (
JOURNALEDadded), 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);Nonewhen 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
relayablefacet of the event pointP, its codecCodec::of::<P>(): usable in aconsttable and at run time alike (.facets(&[relayable_event::<DocChanged>()]),PointSpec::new(…).facet(relayable_event::<DocChanged>())). - relayable_
request - The
relayablefacet of the request pointP, its codecCodec::request::<P>(): usable in aconsttable and at run time alike.
Type Aliases§
- Authority
- Decides whether what crosses in may be taken (
Relay::add_authority):Err(reason)refuses it. - Decode
Fn - Reads an event’s input back from text, its type erased.
- Decode
Value Fn - Reads a request’s value back from text into a value of the point’s type, its type erased, replacing it.
- Encode
Fn - Writes an event’s input as text, its type erased;
Nonewhen the input is not of the point’s type. - Encode
Value Fn - Writes a request’s value as text, its type erased;
Nonewhen the value is not of the point’s type.