enum

RUST 0x05 Enum

北城余情 提交于 2019-12-04 01:21:48
RUST 0x05 Enum 1 定义一个Enum 如: enum IpAddrKind { V4, V6, } enum的值只能是它的变量中的一个。 Enum Values 可以像这样创建实例: let four = IpAddrKind::V4; let six = IpAddrKind::V6; enum里的变量是在其namespace下的,所以要用 :: 。这时 IpAddrKind::V4 和 IpAddrKind::V6 是同一种类型—— IpAddrKind ,所以可以像这样: fn route(ip_kind: IpAddrKind) { route(IpAddrKind::V4); route(IpAddrKind::V6); 可以这样将enum和struct组合使用: enum IpAddrKind { V4, V6, } struct IpAddr { kind: IpAddrKind, address: String, } let home = IpAddr { kind: IpAddrKind::V4, address: String::from("127.0.0.1"), }; let loopback = IpAddr { kind: IpAddrKind::V6, address: String::from("::1"), };

Mysql之数据类型

て烟熏妆下的殇ゞ 提交于 2019-12-03 16:48:18
一、整形的显示宽度   在mysql的数据类型中有如下定义, 整型类型(显示宽度)   注意,正确的理解,其实是显示宽度, 因为整型的显示宽度,对数值大小无影响,只是当设置了zerofill的时候,在显示的时候补0而已。    从上面的显示我们看到,设置了宽度为5, 并且zerofill了 ,这样在查询的时候,会在前面自动补0。 宽度可以不设置,因为整数数据类型都有默认的显示宽度,不设就采用默认的。   另外,即使设置了显示宽度,也能赋超过显示宽度的值,整型的显示宽度仅仅用于显示补0。   二、浮点型与定点型   在mysql的数据类型中浮点型分为两种,float()与double()类型,定点型为decimal()。 数据类型(M,D) M:精度,数据的总长度; D:标度,小数点后的长度;   其区别在于: 当不指定精度时,Float、Double默认会保存实际精度,而Decimal默认是整数; 当标度不够时,都会四舍五入,但Decimal会警告信息。    三、日期与时间类型   MySQL日期时间所有种类如下: 类型 字节数 取值范围 零值 YEAR 1 1901~2155 0000 DATE 4 1000-01-01~9999-12-31 0000:00:00 TIME 3 -838:59:59~838:59:59 00:00:00 DATETIME 8 1000-01

TypeScript-初级-04-枚举

情到浓时终转凉″ 提交于 2019-12-03 15:19:54
枚举 枚举(Enum)类型用于取值被限定在一定范围内的场景,比如一周只能有七天,颜色限定为红绿蓝等。 简单的例子 枚举使用 enum 关键字来定义: enum Days {Sun, Mon, Tue, Wed, Thu, Fri, Sat}; 枚举成员会被赋值为从 0 开始递增的数字,同时也会对枚举值到枚举名进行反向映射: enum Days {Sun, Mon, Tue, Wed, Thu, Fri, Sat}; console.log(Days["Sun"] === 0); // true console.log(Days["Mon"] === 1); // true console.log(Days["Tue"] === 2); // true console.log(Days["Sat"] === 6); // true console.log(Days[0] === "Sun"); // true console.log(Days[1] === "Mon"); // true console.log(Days[2] === "Tue"); // true console.log(Days[6] === "Sat"); // true 事实上,上面的例子会被编译为: var Days; (function (Days) { Days[Days["Sun"] = 0] =

unity enum是一个好东西

删除回忆录丶 提交于 2019-12-03 15:11:13
在 C#中, 枚举, 非常方便, 绝对是,简单,实用,无负作用, 我们举个例子, 假如,我们有很多类型, public const int TYPE_A = 1; public const int TYPE_B = 2; public const int TYPE_C = 3; 最开始,只有三个的时候,我们还好管理, 但是,随着类型的增多,变化, 很可能会出现, TYPE_AB 是101, 而 TYPE_CB 也是 101, 这是我们编码中出现的意外,而当我们没有发现这个错误的时候, 可能游戏中就会出现 “时灵时不灵”的问题, 我们知道有问题,但是,问题却是“随机”出现的,我们知道有问题,却为哪里出了问题,头疼不已。 如果 A ,B ,C 三人都有钥匙,那么,钱丢了,我们的怀疑对象,就有三个人, 如果只有A有钥匙,那么,怀疑对象,就变为了一人。 使用 enum ,我们想要犯错,都很难,很难,因为,我们没有 钥匙。 这就好像是,一个门,小偷很轻易就能打开,他就可能控制不了欲望,就进去行窃了, 而这个门,忙活了半个小时,也打不开,小偷此时,就是想犯错误,都没有犯错误的机会。 假如,你总是控制不住,想玩一个网络游戏,如果此时断网了,甚至断电了,你此时,还能怎样? 假如,我们使用的是 unity 自带的 MONO 控制器, 当我们使用枚举的时候, public enum PLAT {

C#获取枚举描述文本

只谈情不闲聊 提交于 2019-12-03 14:10:37
定义一个表示方向的枚举: public enum Position { [Description("上")] Up, [Description("下")] Down, [Description("左")] Left, [Description("右")] Right } 获取枚举的描述: public static string GetDescription<TEnum>(TEnum @enum) { FieldInfo fieldInfo = @enum.GetType().GetField(@enum.ToString()); DescriptionAttribute[] descriptionAttributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); return descriptionAttributes.Length > 0 ? descriptionAttributes[0].Description : @enum.ToString(); } 使用示例: Position position = Position.Left; var description = GetDescription(position); //

Android Room type convert multiple enum types

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am writing a type converter for my Room database. I have a couple custom enum classes and I want to convert all of them to its ordinals when stored in the database. So, instead of writing the following for every single class, is there any way to simplify it (such as pass in a generic enum type)? class Converter { @TypeConverter fun toOrdinal(type: TypeA): Int = type.ordinal @TypeConverter fun toTypeA(ordinal: Int): TypeA = TypeA.values().first { it.ordinal == ordinal } @TypeConverter fun toOrdinal(type: TypeB): Int = type.ordinal

JSON Parsing using Decodable

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to parse the following JSON using decodable protocol. I am able to parse string value such as roomName . But I am not able to map/parse owners, admins, members keys correctly. For eg, using below code, I can able to parse if the values in owners/members are coming as an array. But in some cases, the response will come as a string value(see owners key in JSON), but I am not able to map string values. Note: Values of admins, members, owners can be string or array (see owners and members keys in JSON) { "roomName": "6f9259d5-62d0

Override valueof() and toString() in Java enum

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The values in my enum are words that need to have spaces in them, but enums can't have spaces in their values so it's all bunched up. I want to override toString() to add these spaces where I tell it to. I also want the enum to provide the correct enum when I use valueOf() on the same string that I added the spaces to. For example: public enum RandomEnum { StartHere, StopHere } Call toString() on RandomEnum whose value is StartHere returns string "Start Here" . Call valueof() on that same string ( "Start Here" ) returns enum value StartHere

Cant bind enum to combobox wpf mvvm

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: A have read a lot of method about the ways of binding enum to combobox. So now in .Net 4.5 it should be pretty ease. But my code dont work. Dont really understand why. xaml: <Window x:Class = "SmartTrader.Windows.SyncOfflineDataWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "SyncOfflineDataWindow" Height = "300" Width = "300" > <Grid> <StackPanel> <ComboBox ItemsSource = "{Binding StrategyTypes}" SelectedItem = "{Binding StrategyType}" />

Create Custom Enum Type

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to create a custom enum type for the custom control like https://sapui5.hana.ondemand.com/docs/api/symbols/sap.ui.core.ValueState.html#.Error . My questions are: How can I create an enum type? On the custom control, you will be able only to pass property enum type. How can I validate if the given enum is valid or not? 回答1: In order to create an enum type in UI5, there are certain rules to take into account: The enum definition must be a plain object . Internally, it's validated via jQuery.isPlainObject . Each key-value pair