pub struct Frame<'a> { /* private fields */ }
Expand description
Represents some data wrapped in a frame in order to ship it over the network. The format is
simple and follows {len}{item}
where len
is the length of the item as a u64
.
Implementations§
Source§impl Frame<'_>
impl Frame<'_>
Sourcepub const HEADER_SIZE: usize = 8usize
pub const HEADER_SIZE: usize = 8usize
Total bytes to use as the header field denoting a frame’s size.
Sourcepub fn is_nonempty(&self) -> bool
pub fn is_nonempty(&self) -> bool
Returns true if the frame is comprised of some bytes.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Writes the frame to a new Vec
of bytes, returning them on success.
Sourcepub fn write(&self, dst: &mut BytesMut)
pub fn write(&self, dst: &mut BytesMut)
Writes the frame to the end of dst
, including the header representing the length of the
item as part of the written bytes.
Sourcepub fn read(src: &mut BytesMut) -> Option<OwnedFrame>
pub fn read(src: &mut BytesMut) -> Option<OwnedFrame>
Attempts to read a frame from src
, returning Some(Frame)
if a frame was found
(including the header) or None
if the current src
does not contain a frame.
Sourcepub fn available(src: &BytesMut) -> bool
pub fn available(src: &BytesMut) -> bool
Checks if a full frame is available from src
, returning true if a frame was found false
if the current src
does not contain a frame. Does not consume the frame.
Sourcepub fn as_borrowed(&self) -> Frame<'_>
pub fn as_borrowed(&self) -> Frame<'_>
Returns a new frame which is identical but has a lifetime tied to this frame.
Sourcepub fn into_owned(self) -> OwnedFrame
pub fn into_owned(self) -> OwnedFrame
Converts the Frame
into an owned copy.
If you construct the frame from an item with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.
This is different from just cloning. Cloning the frame will just copy the references, and thus the lifetime will remain the same.
Trait Implementations§
Source§impl Extend<u8> for Frame<'_>
impl Extend<u8> for Frame<'_>
Source§fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)impl<'a> Eq for Frame<'a>
impl<'a> StructuralPartialEq for Frame<'a>
Auto Trait Implementations§
impl<'a> Freeze for Frame<'a>
impl<'a> RefUnwindSafe for Frame<'a>
impl<'a> Send for Frame<'a>
impl<'a> Sync for Frame<'a>
impl<'a> Unpin for Frame<'a>
impl<'a> UnwindSafe for Frame<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)