pub trait JsonBufferReader: Send {
// Required methods
fn poll_recv_json(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Value, DbError>>;
fn try_recv_json(&mut self) -> Result<Value, DbError>;
// Provided methods
fn poll_recv_json_bytes(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Vec<u8>, DbError>> { ... }
fn try_recv_json_bytes(&mut self) -> Result<Vec<u8>, DbError> { ... }
}Expand description
Reader trait for consuming JSON-serialized values from a buffer.
Type-erased reader that subscribes to a typed buffer and emits either
serde_json::Value or already-serialized JSON bytes. Used by the remote
access protocol for subscriptions.
This trait enables subscribing to a buffer without knowing the concrete type T
at compile time, by serializing values to JSON on each poll.
Object-safe and poll-based for the same reason as BufferReader.
Consumers use the JsonReader handle, whose
receive methods are async wrappers over the corresponding poll methods
and do not box a per-message future.
§Requirements
- Record must be configured with
.with_remote_access() - Only available with the
remotefeature (requires serde_json)
Required Methods§
Sourcefn poll_recv_json(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Value, DbError>>
fn poll_recv_json( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Value, DbError>>
Poll for the next value, serialized to JSON.
Returns Poll::Ready(Ok(json)) when a value is available and
serializes successfully, Poll::Ready(Err(..)) on lag/closure/serialize
failure, or Poll::Pending after registering cx.waker().
§Returns
Ok(JsonValue)- Successfully received and serialized valueErr(BufferLagged)- Missed messages (can continue reading)Err(BufferClosed)- Buffer closed (graceful shutdown)Err(SerializationFailed)- Failed to serialize value to JSON
Sourcefn try_recv_json(&mut self) -> Result<Value, DbError>
fn try_recv_json(&mut self) -> Result<Value, DbError>
Non-blocking receive as JSON — returns immediately.
Returns Err(DbError::BufferEmpty) if no pending values.
Provided Methods§
Sourcefn poll_recv_json_bytes(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Vec<u8>, DbError>>
fn poll_recv_json_bytes( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Vec<u8>, DbError>>
Poll for the next value as owned JSON bytes.
Existing implementations inherit a compatibility path that calls
poll_recv_json and serializes the returned
tree. Typed record readers override this to encode T directly.
Sourcefn try_recv_json_bytes(&mut self) -> Result<Vec<u8>, DbError>
fn try_recv_json_bytes(&mut self) -> Result<Vec<u8>, DbError>
Non-blocking receive as owned JSON bytes.
Existing implementations inherit a compatibility path through
try_recv_json.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".