pub struct Angle(pub u8);Expand description
A rotation angle encoded in steps of 1/256 of a full turn.
The wire value is a single byte. Because 256 steps represent one full turn, the value wraps around and its signedness does not matter.
§Examples
use mcproto_types::{TypeCodec, basic::Angle};
let angle = Angle(64);
let mut encoded = Vec::new();
angle.encode(&mut encoded)?;
assert_eq!(encoded, [64]);
let mut input = encoded.as_slice();
assert_eq!(Angle::decode(&mut input)?, angle);
assert_eq!(angle.to_degrees(), 90.0);
assert!((angle.to_radians() - std::f64::consts::FRAC_PI_2).abs() < 1e-12);Tuple Fields§
§0: u8The raw angle step count, from 0 through 255.
Implementations§
Source§impl Angle
impl Angle
Sourcepub fn to_degrees(&self) -> f64
pub fn to_degrees(&self) -> f64
Returns the angle in degrees.
A full turn of 256 steps is equivalent to 360 degrees.
Sourcepub fn to_radians(&self) -> f64
pub fn to_radians(&self) -> f64
Returns the angle in radians.
A full turn of 256 steps is equivalent to 2π radians.
Trait Implementations§
impl Copy for Angle
Source§impl EnumRepr for Angle
impl EnumRepr for Angle
Source§fn from_discriminant(value: i128) -> Option<Self>
fn from_discriminant(value: i128) -> Option<Self>
Converts a Rust enum discriminant into this wire representation.
Source§fn discriminant(&self) -> i128
fn discriminant(&self) -> i128
Returns this representation as a numeric enum discriminant.
impl Eq for Angle
impl StructuralPartialEq for Angle
Auto Trait Implementations§
impl Freeze for Angle
impl RefUnwindSafe for Angle
impl Send for Angle
impl Sync for Angle
impl Unpin for Angle
impl UnsafeUnpin for Angle
impl UnwindSafe for Angle
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.