pub struct Parser { /* private fields */ }Expand description
Streaming RESP2 parser.
Feed data incrementally and extract frames as they become available.
§Examples
use bytes::Bytes;
use resp_rs::resp2::{Parser, Frame};
let mut parser = Parser::new();
parser.feed(Bytes::from("+HEL"));
assert!(parser.next_frame().unwrap().is_none());
parser.feed(Bytes::from("LO\r\n"));
let frame = parser.next_frame().unwrap().unwrap();
assert_eq!(frame, Frame::SimpleString(Bytes::from("HELLO")));Implementations§
Source§impl Parser
impl Parser
Sourcepub fn next_frame(&mut self) -> Result<Option<Frame>, ParseError>
pub fn next_frame(&mut self) -> Result<Option<Frame>, ParseError>
Try to extract the next complete frame.
Returns Ok(None) if there isn’t enough data yet.
Returns Err on protocol errors (buffer is cleared).
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Number of bytes currently buffered.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Parser
impl RefUnwindSafe for Parser
impl Send for Parser
impl Sync for Parser
impl Unpin for Parser
impl UnsafeUnpin for Parser
impl UnwindSafe for Parser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more