Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
tephra-client
A TCP client for a tephra event store, speaking its
length-prefixed protobuf-over-TCP protocol. It ships a blocking Client and, behind the async
feature, a concurrent AsyncClient that multiplexes many requests over a control socket plus a pool
of bulk read sockets.
The client speaks clean Rust types: the shared vocabulary from
tephra-types (Query, QueryItem, AppendCondition,
Position, EventType, Tag, Tags) plus a friendly owned Event and SequencedEvent. The wire
protobuf types stay an implementation detail behind them.
Requires a tephra server on 0.4 or above, which speaks the mandatory Hello handshake this client
opens with. Optional features:
async: the multiplexingAsyncClient, on Tokio.tls: TLS 1.3 for the blocking client.async-tls: TLS for the async client.
Quick start
The blocking Client opens one connection and carries a single request at a time, so give each
thread its own, or use the AsyncClient below.
use ;
Concepts
- Event: a type, a set of tags, and an opaque payload, built with
Event::new. - Position: a dense, 1-based global order.
Position::ZEROis the start cursor;Position::MAXis the "from the tip" cursor for a backward read. - Query:
Query::all()matches everything;Query::itemsOR's items, where each item AND's its tags and OR's its types. - AppendCondition: a dynamic consistency boundary. Reject the append if any event after its
afterposition matches the query; omitafterfor the uniqueness-guard pattern.
Reads and pagination
read returns a lazy ReadStream; read_all drains one into a Vec and returns the watermark.
read_back and read_all_back are the newest-first duals, taking a before upper bound, so
Position::MAX starts at the tip.
after (exclusive) and a limit compose into a stateless pagination cursor:
let mut cursor = ZERO;
loop
Subscriptions
subscribe catches up on matching events, then tails new ones live, yielding a CaughtUp marker
each time it reaches the live edge.
use SubEvent;
let = client.subscribe?;
for item in &mut stream
cancel.cancel;
A subscription does not end on its own: drop the stream, or call cancel on the paired
SubscribeCancel.
Async client
With the async feature, AsyncClient multiplexes many concurrent requests over one control socket
plus a pool of bulk read sockets. Its methods take &self, so a single client drives concurrent work
on a Tokio runtime.
use ;
let client = connect.await?;
// Both futures borrow the same client; the requests are multiplexed on one connection.
let = join!;
a?;
b?;
let = client.read_all.await?;
TLS
With the tls feature, Client::connect_tls verifies the server certificate (TLS 1.3,
server-authenticated). Build the config from the system roots, or from a custom CA for a self-signed
certificate.
use ;
// Verify against the system roots (a public CA):
let config = config_with_native_roots?;
let mut client = connect_tls?;
// Or trust a private CA for a self-signed certificate:
let config = config_with_custom_ca?;
let mut client = connect_tls?;
Authentication
When the server requires a bearer token, pass it to a *_with connect variant, so a rejected token
fails the connect rather than the first request. Pair it with TLS so the token does not cross an
unencrypted hop.
// Blocking, over TLS:
let config = config_with_native_roots?;
let mut client = connect_tls_with?;
The async client carries the token on AsyncClientConfig::auth_token, and every socket in its
control-plus-bulk pool authenticates independently.
Errors
A call returns ClientError on failure. The Server variant carries the wire code, a message,
a retryable flag (set for an advisory same-batch append conflict), and a conflict_position for a
durable one; Protocol, UnexpectedEof, and Frame cover transport and framing failures. The
client does no automatic retries or reconnection.
Related crates
tephra-server: the server this client connects to.tephra-types: the shared vocabulary.tephra: the embedded engine, if you do not need the network.
Clients for other languages: tephra-go and, for JavaScript, @tephradb/client.
License
Licensed under the Apache License, Version 2.0.