hi i'm a embedded developer, in embedded world we always encode multiple bytes and for send or receive various of data and get one byte as data type now i know rust support C-like
enum HeaderType {
Unknown = 0,
Notification = 1,
API = 2,
}
and in rust enum can have specific data like this
enum MyEnum {
A(i8),
B(f32),
C(u8),
}
now the solution i found in rust for my work is
#[derive(Copy, Clone)]
#[repr(C)]
pub union Params {
unknown: usize,
notification: f32,
api: usize,
}
#[derive(Debug, Copy, Clone)]
#[repr(u8)]
pub enum HeaderType {
Unknown = 0,
Notification = 1,
API = 2,
}
#[derive(Debug, Clone)]
pub struct SocketHeader {
header_type: HeaderType,
params: Params,
}
in above code header_type hold type of data and params is union that hold data
i think it will be good if can have rust code like this
enum SocketHeader {
Unknown(usize) = 0,
Notification(f32) = 1,
API(usize) = 2,
}
now we can have enum id and data