Commit fe0a1f48 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

impl from to msg

parent 950409b2
use std::mem::transmute; use std::mem::transmute;
#[repr(u8)]
#[derive(Clone)] #[derive(Clone)]
pub enum Msg { pub enum Msg {
Hello = 0, Hello = 0,
...@@ -37,7 +38,7 @@ pub enum Msg { ...@@ -37,7 +38,7 @@ pub enum Msg {
impl Msg { impl Msg {
pub fn to_int(&self) -> u8 { pub fn to_int(&self) -> u8 {
self.clone() as u8 self.clone().into()
} }
pub fn from(msg_code: u8) -> Self { pub fn from(msg_code: u8) -> Self {
if msg_code > 21 { if msg_code > 21 {
...@@ -46,3 +47,9 @@ impl Msg { ...@@ -46,3 +47,9 @@ impl Msg {
unsafe { transmute::<u8, Msg>(msg_code) } unsafe { transmute::<u8, Msg>(msg_code) }
} }
} }
impl From<Msg> for u8 {
fn from(value: Msg) -> Self {
value as u8
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment