官术网_书友最值得收藏!

  • Rust Programming Cookbook
  • Claus Matzinger
  • 106字
  • 2021-06-24 12:27:47

Creating meaningful numbers with enums

Enums, short for enumerations, are well-known programming constructs that many languages feature. These special cases of types allow a number to be mapped to a name. This can be used to tie constants together under a single name and lets us declare values as variants. For example, we could have pi, as well as Euler's number, as variants of an enum, MathConstants. Rust is no different, but it can go a lot further. Instead of simply relying on naming numbers, Rust allows enums the same flexibility as other Rust types have. Let's see what this means in practice.

主站蜘蛛池模板: 化德县| 通江县| 左云县| 于都县| 常州市| 西宁市| 潼南县| 南昌县| 莱西市| 五原县| 施秉县| 申扎县| 怀化市| 桃园市| 大田县| 咸阳市| 高邮市| 宣武区| 呼图壁县| 桦甸市| 沙雅县| 兴国县| 府谷县| 呼玛县| 武强县| 渝北区| 克山县| 万荣县| 留坝县| 中牟县| 临沧市| 深州市| 玉溪市| 勐海县| 东宁县| 昌宁县| 汉寿县| 铜山县| 芒康县| 永泰县| 潞城市|