Struct distant_net::common::Frame  
source · 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)source§impl<'a> PartialEq<Frame<'a>> for Frame<'a>
 
impl<'a> PartialEq<Frame<'a>> for Frame<'a>
impl<'a> Eq for Frame<'a>
impl<'a> StructuralEq for Frame<'a>
impl<'a> StructuralPartialEq for Frame<'a>
Auto Trait Implementations§
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> ToHex for Twhere
    T: AsRef<[u8]>,
 
impl<T> ToHex for Twhere T: AsRef<[u8]>,
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)