[−][src]Struct mini_redis::Connection
Send and receive Frame
values from a remote peer.
When implementing networking protocols, a message on that protocol is
often composed of several smaller messages known as frames. The purpose of
Connection
is to read and write frames on the underlying TcpStream
.
To read frames, the Connection
uses an internal buffer, which is filled
up until there are enough bytes to create a full frame. Once this happens,
the Connection
creates the frame and returns it to the caller.
When sending frames, the frame is first encoded into the write buffer. The contents of the write buffer are then written to the socket.
Implementations
impl Connection
[src]
pub fn new(socket: TcpStream) -> Connection
[src]
Create a new Connection
, backed by socket
. Read and write buffers
are initialized.
pub async fn read_frame<'_>(&'_ mut self) -> Result<Option<Frame>>
[src]
Read a single Frame
value from the underlying stream.
The function waits until it has retrieved enough data to parse a frame.
Any data remaining in the read buffer after the frame has been parsed is
kept there for the next call to read_frame
.
Returns
On success, the received frame is returned. If the TcpStream
is closed in a way that doesn't break a frame in half, it returns
None
. Otherwise, an error is returned.
pub async fn write_frame<'_, '_>(&'_ mut self, frame: &'_ Frame) -> Result<()>
[src]
Write a single Frame
value to the underlying stream.
The Frame
value is written to the socket using the various write_*
functions provided by AsyncWrite
. Calling these functions directly on
a TcpStream
is not advised, as this will result in a large number of
syscalls. However, it is fine to call these functions on a buffered
write stream. The data will be written to the buffer. Once the buffer is
full, it is flushed to the underlying socket.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl !UnwindSafe for Connection
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> WithSubscriber for T
[src]
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
[src]
S: Into<Dispatch>,