Enum MessageType

Source
pub enum MessageType {
    Null,
    Get,
    Reply,
    Error,
    Shutdown,
    Unknown,
}
Expand description

A listing of all the different kinds of message types that a Message can be composed of.

§Description

The Message Type variants are put at the beginning of a network message, and determine what kind of message the network message will be. Each variant of the MessageType enum maps to a u8 integer, a MessageType variant can also be created from a u8 integer.

§u8 Variant Mappings

  • Null == 0
  • Get == 1
  • Reply == 2
  • Error == 3
  • Shutdown == 4
  • Unknown >= 5

§Examples

use network_audio_protocol::MessageType;

let message_type: MessageType = MessageType::from(1);
assert_eq!(message_type, MessageType::Get);
assert_eq!(message_type.to_string(), String::from("Get"));

println!("Message Type: {}, maps to: {}", message_type, message_type.as_u8());

The above code creates a MessageType variant from the u8 integer 1, confirms that it is equal to MessageType::Get, turns the MessageType into a String, and compares it to another string value, and finally prints the MessageType and its corresponding u8 value

Variants§

§

Null

The Null variant is used to create a null, or empty message.

§

Get

The Get variant is used to create a message that contains a request within it.

§

Reply

The Reply variant is used to create a message that contains data to fufill a Get request.

§

Error

The Error variant is used to create a message indicating an error occurred.

§

Shutdown

The Shutdown variant is used to create a shutdown / termination message.

§

Unknown

The Unkown variant is not used to make any messages, but rather to represent a message of an unknown type.

Implementations§

Source§

impl MessageType

Source

pub fn as_u8(&self) -> u8

Returns the corresponding u8 integer value for the used MessageType variant. Unlike Into it does not consume self.

Trait Implementations§

Source§

impl Debug for MessageType

Source§

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

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

impl Display for MessageType

Source§

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

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

impl From<u8> for MessageType

Source§

fn from(byte: u8) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for MessageType

Source§

fn eq(&self, other: &MessageType) -> 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 StructuralPartialEq for MessageType

Auto Trait Implementations§

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.