pub enum Either<X, Y> {
X(X),
Y(Y),
}Expand description
A boolean-selected value of protocol type X or Y.
The wire representation begins with a Boolean. A true marker is
followed by an X value, while a false marker is followed by a Y value:
0x01 + X
0x00 + YBoth branch types must implement TypeCodec. The enum variant binds the
marker to the matching payload, so an in-memory marker/payload mismatch
cannot be represented.
§Examples
use mcproto_types::{Either, TypeCodec, UnsignedByte, VarInt};
let x = Either::<UnsignedByte, VarInt>::X(UnsignedByte(0xab));
let mut encoded = Vec::new();
x.encode(&mut encoded)?;
assert_eq!(encoded, [0x01, 0xab]);
assert_eq!(Either::decode(&mut encoded.as_slice())?, x);
let y = Either::<UnsignedByte, VarInt>::Y(VarInt(25565));
let mut encoded = Vec::new();
y.encode(&mut encoded)?;
assert_eq!(encoded, [0x00, 0xdd, 0xc7, 0x01]);See the official Either X or Y protocol documentation.
Variants§
Implementations§
Trait Implementations§
impl<X: Copy, Y: Copy> Copy for Either<X, Y>
impl<X: Eq, Y: Eq> Eq for Either<X, Y>
impl<X: PartialEq, Y: PartialEq> StructuralPartialEq for Either<X, Y>
Auto Trait Implementations§
impl<X, Y> Freeze for Either<X, Y>
impl<X, Y> RefUnwindSafe for Either<X, Y>where
X: RefUnwindSafe,
Y: RefUnwindSafe,
impl<X, Y> Send for Either<X, Y>
impl<X, Y> Sync for Either<X, Y>
impl<X, Y> Unpin for Either<X, Y>
impl<X, Y> UnsafeUnpin for Either<X, Y>where
X: UnsafeUnpin,
Y: UnsafeUnpin,
impl<X, Y> UnwindSafe for Either<X, Y>where
X: UnwindSafe,
Y: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ContextualCodec for Twhere
T: TypeCodec,
impl<T> ContextualCodec for Twhere
T: TypeCodec,
Source§fn encode_with_context(
&self,
writer: &mut impl Write,
_context: &Context,
) -> Result<(), CodecError>
fn encode_with_context( &self, writer: &mut impl Write, _context: &Context, ) -> Result<(), CodecError>
Encodes this value using context supplied by its enclosing structure.
Source§fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
fn decode_with_context(
reader: &mut impl Read,
_context: &Context,
) -> Result<T, CodecError>where
T: Sized,
Decodes this value using context supplied by its enclosing structure.