Skip to main content

FrameReader

Struct FrameReader 

Source
pub struct FrameReader<F: Framer, const MAX_MSG_SIZE: usize> { /* private fields */ }
Expand description

Represents an abstraction for reading exactly oen frame from the TcpStream. Each call to the Self::read_frame will issue a Read::read system call on the underlying TcpStream. which will capture any bytes read into internal accumulator implemented as a BytesMut. This internal buffer will be passed to the generic impl of Framer::get_frame where it is user’s responsibility to inspect the buffer and split off a single frame.

§Generic Parameters

  • F - A type that implements the Framer trait. This is used to split off a single frame from the internal buffer.
  • MAX_MSG_SIZE - The maximum size of a single frame. This is used to pre-allocate the internal buffer. Set this number to the maximum size of a single frame for your protocol.

Implementations§

Source§

impl<F: Framer, const MAX_MSG_SIZE: usize> FrameReader<F, MAX_MSG_SIZE>

Source

pub fn new(con_id: ConId, reader: TcpStream) -> FrameReader<F, MAX_MSG_SIZE>

Creates a new instance of FrameReader

§Arguments
  • con_id - ConId a unique identifier for the connection and used for logging
  • reader - TcpStream the underlying stream that will be used for reading
Source

pub fn read_frame(&mut self) -> Result<Option<Bytes>, Error>

Reads exactly one frame from the underlying TcpStream and returns it as a [Some(Bytes)] or None if the connection was closed.

§Note

If the FrameWriter pair is dropped then this method will return a [Ok(None)].

Trait Implementations§

Source§

impl<F: Debug + Framer, const MAX_MSG_SIZE: usize> Debug for FrameReader<F, MAX_MSG_SIZE>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<F: Framer, const MAX_MSG_SIZE: usize> Display for FrameReader<F, MAX_MSG_SIZE>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<F: Framer, const MAX_MSG_SIZE: usize> Drop for FrameReader<F, MAX_MSG_SIZE>

Source§

fn drop(&mut self)

Will shutdown the underlying std::net::TcpStream in both directions. This way the peer connection will receive a TCP FIN flag and and once it reaches the peer FrameWriter it will get a ErrorKind::BrokenPipe error which in turn shall issue a Shutdown::Write

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<F, const MAX_MSG_SIZE: usize> Freeze for FrameReader<F, MAX_MSG_SIZE>

§

impl<F, const MAX_MSG_SIZE: usize> RefUnwindSafe for FrameReader<F, MAX_MSG_SIZE>
where F: RefUnwindSafe,

§

impl<F, const MAX_MSG_SIZE: usize> Send for FrameReader<F, MAX_MSG_SIZE>
where F: Send,

§

impl<F, const MAX_MSG_SIZE: usize> Sync for FrameReader<F, MAX_MSG_SIZE>
where F: Sync,

§

impl<F, const MAX_MSG_SIZE: usize> Unpin for FrameReader<F, MAX_MSG_SIZE>
where F: Unpin,

§

impl<F, const MAX_MSG_SIZE: usize> UnsafeUnpin for FrameReader<F, MAX_MSG_SIZE>

§

impl<F, const MAX_MSG_SIZE: usize> UnwindSafe for FrameReader<F, MAX_MSG_SIZE>
where F: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.