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
sourceimpl 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 try_to_bytes(&self) -> Result<Vec<u8>>
pub fn try_to_bytes(&self) -> Result<Vec<u8>>
Writes the frame to a new Vec of bytes, returning them on success
sourcepub fn write(&self, dst: &mut BytesMut) -> Result<()>
pub fn write(&self, dst: &mut BytesMut) -> Result<()>
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) -> Result<Option<OwnedFrame>>
pub fn read(src: &mut BytesMut) -> Result<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
sourceimpl Extend<u8> for Frame<'_>
impl Extend<u8> for Frame<'_>
sourcefn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere
T: AsRef<[u8]>,
sourcefn 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) Read moresourcefn 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) Read more