Skip to main content

Client

Struct Client 

Source
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

Source

pub fn new( endpoint: impl Into<String>, token: impl Into<String>, options: Options, ) -> Self

Build a client for an explicit endpoint and token.

Source

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.

Source

pub fn from_values( endpoint: Option<&str>, token: Option<&str>, options: Options, ) -> Option<Self>

Build a client from explicit endpoint and token 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 yields None.

Source

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.

Source

pub fn connected(&self) -> bool

Whether the handshake completed and the link is still up.

Source

pub fn session_id(&self) -> Option<&str>

The id the driver assigned, or None before the handshake.

Source

pub fn revision(&self) -> i64

The last revision this client published.

Source

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.

Source

pub fn limits(&self) -> &Limits

The ceilings in force, as negotiated by hello-ack.

Source

pub fn close(&mut self)

Drop the session. The application keeps running.

Source

pub fn fail( &mut self, code: &str, message: impl Into<String>, ) -> Result<(), Error>

Send a typed fatal producer-contract error and close the channel.

Source

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.

Source

pub fn snapshots_sent(&self) -> u64

Whole trees this client has published.

Source

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.

Source

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.

Source

pub fn log_message( &mut self, level: LogLevel, message: impl Into<String>, ) -> bool

Convenience for the common call: a level and a message.

Source

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, to process driver control messages without blocking.

§Errors

Returns Error::Io if the channel broke, or Error::Parse if the driver sent something the contract forbids.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.