pub struct Client { /* private fields */ }Expand description
One semantic session: handshake, snapshot publishing, render markers.
The client owns the revision counter; an adapter never picks its own.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(
endpoint: impl Into<String>,
token: impl Into<String>,
options: Options,
) -> Self
pub fn new( endpoint: impl Into<String>, token: impl Into<String>, options: Options, ) -> Self
Build a client for an explicit endpoint and token.
Sourcepub fn qualified_observations(&self) -> bool
pub fn qualified_observations(&self) -> bool
Whether this client negotiated evidence-qualified protocol v2.
Snapshot producers must know this before observing a frame because v1 forbids qualified geometry while v2 requires it on every node.
Sourcepub fn from_env(options: Options) -> Option<Self>
pub fn from_env(options: Options) -> Option<Self>
Build a client from TERMWRIGHT_*, or None when not instrumented.
This is the dormant rule in one function: no endpoint or no token means no client, and the caller must then open nothing and emit nothing.
Sourcepub fn from_values(
endpoint: Option<&str>,
token: Option<&str>,
protocol: Option<&str>,
options: Options,
) -> Option<Self>
pub fn from_values( endpoint: Option<&str>, token: Option<&str>, protocol: Option<&str>, options: Options, ) -> Option<Self>
Build a client from explicit endpoint, token and protocol values,
applying the same dormant rule as Client::from_env.
Use this when the process manages its own environment, or in tests.
A missing or empty endpoint or token, a protocol other than
termwright/1, or a Windows named pipe all yield None.
Sourcepub fn connect(&mut self, timeout: Duration) -> Result<(), Error>
pub fn connect(&mut self, timeout: Duration) -> Result<(), Error>
Connect, send hello, and wait for hello-ack.
§Errors
Returns Error::Io when the endpoint is unreachable and
Error::HandshakeTimeout when the driver does not answer. A failed
side-channel must not take the application down: callers are expected
to carry on rendering.
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
The id the driver assigned, or None before the handshake.
Sourcepub fn log_budget(&self) -> Option<LogBudget>
pub fn log_budget(&self) -> Option<LogBudget>
The log-channel allowance the driver granted, or None when logs are
disabled — which is the case unless the adapter announced logs.
Sourcepub fn require_full_snapshot(&mut self)
pub fn require_full_snapshot(&mut self)
Make the next publish send a whole tree.
The producer’s obligation from D5: a probe that lost anything from its own stream of facts — a dropped frame, a coalesced burst, a write that failed — must not follow it with a patch. The driver would apply that patch to a tree that never accounted for what was lost, and the divergence would be silent.
Sourcepub fn full_snapshot_required(&self) -> bool
pub fn full_snapshot_required(&self) -> bool
Whether the obligation is outstanding.
Sourcepub fn publish(
&mut self,
snapshot: &mut Snapshot,
) -> Result<Option<String>, Error>
pub fn publish( &mut self, snapshot: &mut Snapshot, ) -> Result<Option<String>, Error>
Publish a snapshot for the next revision and return its marker.
Write the marker to stdout after the render’s last byte: it commits
the bytes that precede it. session_id and revision on the snapshot
are overwritten with the session’s own.
Returns Ok(None) when there is no live session or the driver did not
ask for markers, so a dormant app takes no branch.
§Errors
Returns Error::Validation if the snapshot is invalid — that is an
adapter bug, so it is loud rather than silent — or Error::Io if the
channel broke.
Sourcepub fn deltas_sent(&self) -> u64
pub fn deltas_sent(&self) -> u64
Patches this client has published.
Sourcepub fn snapshots_sent(&self) -> u64
pub fn snapshots_sent(&self) -> u64
Whole trees this client has published.
Sourcepub fn logs_dropped(&self) -> u64
pub fn logs_dropped(&self) -> u64
Records this adapter dropped locally, for being over budget or over a limit. Each one left a gap in the sequence.
Sourcepub fn log(&mut self, record: LogRecord) -> bool
pub fn log(&mut self, record: LogRecord) -> bool
Forward one application log record, if the driver asked for logs.
Returns whether the record went out. A record is dropped when the session is not live, when the driver granted no budget, when this adapter is over its rate, or when the record breaks a limit.
Every attempt consumes a sequence number, dropped or not: the gap left
in seq is precisely how the driver learns records were lost here
rather than in transit.
seq is assigned here whatever the caller set, because the adapter is
the only authority on it: the channel is open to several publishers,
and two of them can pick the same number in good faith. A caller’s own
number is kept as the origin.seq attribute, which is a diagnostic
rather than a promise — it is dropped rather than allowed to push the
record over a limit.
Sourcepub fn log_message(
&mut self,
level: LogLevel,
message: impl Into<String>,
) -> bool
pub fn log_message( &mut self, level: LogLevel, message: impl Into<String>, ) -> bool
Convenience for the common call: a level and a message.
Sourcepub fn poll(&mut self) -> Result<(), Error>
pub fn poll(&mut self) -> Result<(), Error>
Read and answer whatever the driver has sent, without blocking.
Call it on every render tick, or whenever convenient: get-tree
requests are answered from the retained snapshots.
§Errors
Returns Error::Io if the channel broke, or Error::Parse if the
driver sent something the contract forbids.