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<'a> Frame<'a>

source

pub fn new(item: &'a [u8]) -> Self

Creates a new frame wrapping the item that will be shipped across the network.

source

pub fn into_item(self) -> Cow<'a, [u8]>

Consumes the frame and returns its underlying item.

source§

impl Frame<'_>

source

pub const HEADER_SIZE: usize = 8usize

Total bytes to use as the header field denoting a frame’s size.

source

pub fn empty() -> Self

Creates a new frame with no item.

source

pub fn len(&self) -> usize

Returns the len (in bytes) of the item wrapped by the frame.

source

pub fn is_empty(&self) -> bool

Returns true if the frame is comprised of zero bytes.

source

pub fn is_nonempty(&self) -> bool

Returns true if the frame is comprised of some bytes.

source

pub fn as_item(&self) -> &[u8]

Returns a reference to the bytes of the frame’s item.

source

pub fn to_bytes(&self) -> Vec<u8>

Writes the frame to a new Vec of bytes, returning them on success.

source

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.

source

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.

source

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.

source

pub fn as_borrowed(&self) -> Frame<'_>

Returns a new frame which is identical but has a lifetime tied to this frame.

source

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 AsRef<[u8]> for Frame<'_>

source§

fn as_ref(&self) -> &[u8]

Returns a reference to this Frame’s item as bytes.

source§

impl<'a> Clone for Frame<'a>

source§

fn clone(&self) -> Frame<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Frame<'a>

source§

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

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

impl Extend<u8> for Frame<'_>

source§

fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)

Extends the Frame’s item with the provided bytes, allocating an owned Vec underneath if this frame had borrowed bytes as an item.

source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> From<&'a [u8]> for Frame<'a>

source§

fn from(item: &'a [u8]) -> Self

Consumes the byte slice and returns a Frame whose item references those bytes.

source§

impl<'a, const N: usize> From<&'a [u8; N]> for Frame<'a>

source§

fn from(item: &'a [u8; N]) -> Self

Consumes the byte array slice and returns a Frame whose item references those bytes.

source§

impl<'a> PartialEq<&'a [u8]> for Frame<'_>

source§

fn eq(&self, item: &&'a [u8]) -> bool

Test if Frame’s item matches the provided bytes.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, const N: usize> PartialEq<&'a [u8; N]> for Frame<'_>

source§

fn eq(&self, item: &&'a [u8; N]) -> bool

Test if Frame’s item matches the provided bytes.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<[u8]> for Frame<'_>

source§

fn eq(&self, item: &[u8]) -> bool

Test if Frame’s item matches the provided bytes.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const N: usize> PartialEq<[u8; N]> for Frame<'_>

source§

fn eq(&self, item: &[u8; N]) -> bool

Test if Frame’s item matches the provided bytes.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<Frame<'a>> for Frame<'a>

source§

fn eq(&self, other: &Frame<'a>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> Eq for Frame<'a>

source§

impl<'a> StructuralEq for Frame<'a>

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsAny for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts reference to Any
source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

Converts mutable reference to Any
source§

fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>

Consumes and produces Box<dyn Any>
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToHex for Twhere T: AsRef<[u8]>,

source§

fn encode_hex<U>(&self) -> Uwhere U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
source§

fn encode_hex_upper<U>(&self) -> Uwhere U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V