-
Notifications
You must be signed in to change notification settings - Fork 19
Closed
Description
During the discussion of pull request #1544, we discussed that the representation of the opcode list in memory may be improved (#1600), and the code displaying opcodes may need refinement #1544 (review)
I prefer a solution like this. It has disadvantages:
- Requires new dependencies:
num-derive— we haven’t used this before.num-traits— we already use this directly.strum— is used in our subdependencies.
- Will increase build time.
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! num-derive = "0.4.2"
//! num-traits = "0.2.19"
//! strum = { version = "0.27.2", features = ["derive"] }
//! ```
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use strum::IntoStaticStr;
#[derive(FromPrimitive, IntoStaticStr)]
#[repr(u8)]
enum Opcode {
Stop = 0,
Add = 1,
Mul = 2,
}
fn main() {
let s: &str = Opcode::from_u8(2).unwrap().into();
assert_eq!(s, "Mul");
println!("{}", s);
}A part of #1560
As a follow up of #1544 (review)
Metadata
Metadata
Assignees
Labels
No labels