Enum PacketPart

Source
pub enum PacketPart<'a> {
    Null,
    Bool(bool),
    I32(i32),
    I64(i64),
    F32(f32),
    F64(f64),
    Str(&'a str),
    Bytes(&'a [u8]),
}
Expand description

A data type that can be sent as part of a network packet.

The 'a lifetime is the lifetime of the data, if the part contains a string or byte array.

Variants§

§

Null

The packet part is a null.

A null is preserved end-to-end. In OpenComputers 1.7, a null costs six bytes of space in the packet. In OpenComputers 1.8+, it costs 3 bytes.

§

Bool(bool)

The packet part is a boolean.

A boolean is preserved end-to-end. In OpenComputers 1.7, a boolean costs six bytes of space in the packet. In OpenComputers 1.8+, it costs 3 bytes.

§

I32(i32)

The packet part is a 32-bit integer.

In OpenComputers 1.7, an i32 is converted to an F64 on the receiver; therefore, this enumeration element can never appear in a received message. It costs six bytes of space in the packet and is therefore still useful on the sending end as it is cheaper to send an i32 than an f64 (ten bytes).

In OpenComputers 1.8+, an i32 is preserved end-to-end. It costs four bytes if its value is between −32,768 and +32,767, and six bytes otherwise.

§

I64(i64)

The packet part is a 64-bit integer.

In OpenComputers 1.7, an i64 is not permitted.

In OpenComputers 1.8+, an i64 is converted to an I32 and costs the same as that type if its value fits within that type’s range; otherwise, it is preserved end-to-end and costs ten bytes of space in the packet.

§

F32(f32)

The packet part is a 32-bit floating-point number.

In OpenComputers 1.7, an f32 is converted to an F64 on the receiver; therefore, this enumeration element can never appear in a received message. It also costs the same as an F64, ten bytes.

In OpenComputers 1.8+, an f32 is converted to an F64 on the receiver; therefore, this enumeration element can never appear in a received message. It costs six bytes of space in the packet and is therefore still useful on the sending end as it is cheaper to send an f32 than an f64 (ten bytes).

§

F64(f64)

The packet part is a 64-bit floating-point number.

An f64 costs ten bytes of space in the packet and is preserved end-to-end.

§

Str(&'a str)

The packet part is a text string.

An empty str costs three byte of space in the packet. A non-empty str costs two plus the length of its UTF-8-encoded form bytes of space in the packet. It is preserved end-to-end.

§

Bytes(&'a [u8])

The packet part is an array of bytes.

An empty byte array costs three bytes of space in the packet. A non-empty byte array costs two plus its length bytes of space in the packet. It is preserved end-to-end.

Trait Implementations§

Source§

impl<'a> Clone for PacketPart<'a>

Source§

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

Returns a duplicate 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 PacketPart<'a>

Source§

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

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

impl<'buffer, Context> Decode<'buffer, Context> for PacketPart<'buffer>

Source§

fn decode(d: &mut Decoder<'buffer>, _: &mut Context) -> Result<Self, Error>

Decode a value using the given Decoder. Read more
Source§

fn nil() -> Option<Self>

If possible, return a nil value of Self. Read more
Source§

impl<Context> Encode<Context> for PacketPart<'_>

Source§

fn encode<W: Write>( &self, e: &mut Encoder<W>, c: &mut Context, ) -> Result<(), Error<W::Error>>

Encode a value of this type using the given Encoder. Read more
Source§

fn is_nil(&self) -> bool

Is this value of Self a nil value? Read more
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<'a, const N: usize> From<&'a ByteArray<N>> for PacketPart<'a>

Source§

fn from(value: &'a ByteArray<N>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a ByteSlice> for PacketPart<'a>

Source§

fn from(value: &'a ByteSlice) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a ByteVec> for PacketPart<'a>

Source§

fn from(value: &'a ByteVec) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for PacketPart<'a>

Source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<()> for PacketPart<'_>

Source§

fn from((): ()) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for PacketPart<'_>

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for PacketPart<'_>

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for PacketPart<'_>

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for PacketPart<'_>

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for PacketPart<'_>

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for PacketPart<'_>

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for PacketPart<'_>

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for PacketPart<'_>

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for PacketPart<'_>

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for PacketPart<'_>

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl<'a> PartialEq for PacketPart<'a>

Source§

fn eq(&self, other: &PacketPart<'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> PartialOrd for PacketPart<'a>

Source§

fn partial_cmp(&self, other: &PacketPart<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> Copy for PacketPart<'a>

Source§

impl<'a> StructuralPartialEq for PacketPart<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for PacketPart<'a>

§

impl<'a> RefUnwindSafe for PacketPart<'a>

§

impl<'a> Send for PacketPart<'a>

§

impl<'a> Sync for PacketPart<'a>

§

impl<'a> Unpin for PacketPart<'a>

§

impl<'a> UnwindSafe for PacketPart<'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> 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> 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> 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.