pub struct EnumDefinition { /* private fields */ }
Expand description

Enums are special scalars that can only have a defined set of values.

EnumTypeDefinition: Description? enum Name Directives? EnumValuesDefinition?

Detailed documentation can be found in GraphQL spec.

Example

use apollo_encoder::{Argument, Directive, EnumValue, EnumDefinition, Value};

let mut enum_ty_1 = EnumValue::new("CAT_TREE".to_string());
enum_ty_1.description("Top bunk of a cat tree.".to_string());
let enum_ty_2 = EnumValue::new("BED".to_string());
let mut deprecated_directive = Directive::new(String::from("deprecated"));
deprecated_directive.arg(Argument::new(String::from("reason"), Value::String(String::from("Box was recycled."))));
let mut enum_ty_3 = EnumValue::new("CARDBOARD_BOX".to_string());
enum_ty_3.directive(deprecated_directive);

let mut enum_ = EnumDefinition::new("NapSpots".to_string());
enum_.description("Favourite cat nap spots.".to_string());
enum_.value(enum_ty_1);
enum_.value(enum_ty_2);
enum_.value(enum_ty_3);

assert_eq!(
    enum_.to_string(),
    r#""Favourite cat nap spots."
enum NapSpots {
  "Top bunk of a cat tree."
  CAT_TREE
  BED
  CARDBOARD_BOX @deprecated(reason: "Box was recycled.")
}
"#
);

Implementations

Create a new instance of Enum Definition.

Set the enum type as an extension

Set the Enum Definition’s description.

Set the Enum Definitions’s values.

Add a directive.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Create an apollo-encoder node from an apollo-parser one.

Errors

This returns an error if the apollo-parser tree is not valid. The error doesn’t have much context due to TryFrom API constraints: validate the parse tree before using TryFrom if granular errors are important to you.

The type returned in the event of a conversion error.

Create an apollo-encoder node from an apollo-parser one.

Errors

This returns an error if the apollo-parser tree is not valid. The error doesn’t have much context due to TryFrom API constraints: validate the parse tree before using TryFrom if granular errors are important to you.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.