async-graphql/docs/zh-CN/src/define_enum

20 lines
511 B
Plaintext
Raw Normal View History

2020-04-15 03:15:30 +00:00
# 枚举(Enum)
2020-04-16 03:06:09 +00:00
定义一个枚举相当简单,直接给出一个例子。
**Async-graphql会自动把枚举项的名称转换为GraphQL标准的大写加下划线形式你也可以用`name`属性自已定义名称。**
```rust
#[Enum(desc = "One of the films in the Star Wars Trilogy")]
pub enum Episode {
#[item(desc = "Released in 1977.")]
NewHope,
#[item(desc = "Released in 1980.")]
Empire,
// rename to `AAA`
#[item(name="AAA", desc = "Released in 1983.")]
Jedi,
}
```