Struct 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

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

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

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsAny for T
where 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>) -> Box<dyn Any>

Consumes and produces Box<dyn Any>
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where 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 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

fn encode_hex<U>(&self) -> U
where 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) -> U
where 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 T
where T: Clone,

Source§

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

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

Source§

fn vzip(self) -> V