作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以定义一个枚举而不用担心Rust中的内存分配?
假设以下是我的枚举的定义。
pub enum Orientation {
North,
South,
East,
West,
}
Orientation::North
的两个单独的实例?
let o1 = Orientation::North;
let o2 = Orientation::North;
pub enum Orientation {
North,
South,
East,
West,
}
static NORTH: Orientation = Orientation::North;
static SOUTH: Orientation = Orientation::South;
static WEST: Orientation = Orientation::West;
static EAST: Orientation = Orientation::East;
最佳答案
您在运行时询问的代码与您编写的代码相同:
let o1: u8 = 0;
let o2: u8 = 0;
Is there a better (syntactically safer/simpler/cleaner) way to do the same thing?
let o1 = Orientation::North;
let o2 = Orientation::North;
关于enums - Rust中的静态枚举,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62450750/
我是一名优秀的程序员,十分优秀!