pub trait GpsdJsonDecodeAsync: AsyncBufRead {
// Provided methods
fn poll_response<Response>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut Vec<u8>,
) -> Poll<Result<Option<Response>>>
where Response: GpsdJsonResponse { ... }
fn poll_raw(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut Vec<u8>,
) -> Poll<Result<Option<Vec<u8>>>> { ... }
}Expand description
Extension trait for reading GPSD JSON responses from an async buffered reader
This trait provides functionality to asynchronously read and parse GPSD JSON
messages from any type that implements AsyncBufRead. Messages are expected
to be newline-delimited JSON objects.
This is the async equivalent of GpsdJsonDecode.
Provided Methods§
Sourcefn poll_response<Response>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut Vec<u8>,
) -> Poll<Result<Option<Response>>>where
Response: GpsdJsonResponse,
fn poll_response<Response>(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut Vec<u8>,
) -> Poll<Result<Option<Response>>>where
Response: GpsdJsonResponse,
Polls for the next GPSD response message
This method attempts to read and deserialize a single GPSD response message from the async stream. It accumulates data in the provided buffer until a complete message is received (delimited by newline).
§Arguments
self- Pinned mutable reference to the async readercx- The task context for wakingbuf- A reusable buffer for accumulating message data
§Returns
Poll::Ready(Ok(Some(response)))- Successfully parsed response messagePoll::Ready(Ok(None))- End of stream reachedPoll::Ready(Err(_))- I/O or parsing error occurredPoll::Pending- Not enough data available yet
§Example
let mut buf = Vec::new();
let fut = futures::future::poll_fn(|cx| {
Pin::new(&mut *reader).poll_response::<ResponseMessage>(cx, &mut buf)
});
if let Ok(Some(response)) = fut.await {
// Process the response
}Sourcefn poll_raw(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut Vec<u8>,
) -> Poll<Result<Option<Vec<u8>>>>
fn poll_raw( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut Vec<u8>, ) -> Poll<Result<Option<Vec<u8>>>>
Polls for raw GPSD message data without deserialization
This method reads raw bytes from the async stream until a complete message is received (delimited by newline), but returns the raw bytes instead of deserializing them. This is useful when you need to process the raw JSON data or handle messages that don’t fit standard types.
§Arguments
self- Pinned mutable reference to the async readercx- The task context for wakingbuf- A reusable buffer for accumulating message data
§Returns
Poll::Ready(Ok(Some(bytes)))- Complete raw message including newlinePoll::Ready(Ok(None))- End of stream reachedPoll::Ready(Err(_))- I/O error occurredPoll::Pending- Not enough data available yet
§Example
let mut buf = Vec::new();
let fut = futures::future::poll_fn(|cx| {
Pin::new(&mut *reader).poll_raw(cx, &mut buf)
});
if let Ok(Some(raw_msg)) = fut.await {
// Process raw JSON bytes
let json_str = String::from_utf8_lossy(&raw_msg);
println!("Raw message: {}", json_str);
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.