Skip to content

Decorators

The Rust emitter does not define its own TypeSpec decorators. Instead it recognizes a set of decorators from @azure-tools/typespec-client-generator-core (TCGC) and from the TypeSpec standard library that influence how the generated Rust code looks. The supported decorators are documented below.

Source: Azure.ClientGenerator.Core (from @azure-tools/typespec-client-generator-core)

The @@clientOption decorator passes emitter-specific named options to a client, an operation, or a model property. The Rust emitter recognizes the following named options.

Type: boolean

When true, the endpoint() accessor method is not generated on the client struct. Use this when you need to write the method by hand in a customization layer.

@@clientOption(MyClient, "omitEndpointMethod", true);

Type: boolean

When true, a paging operation returns a PageIterator<T> instead of the default Pager<T>. A PageIterator<T> asynchronously yields individual items across all pages, while a Pager<T> yields one page at a time.

@@clientOption(MyClient.listItems, "forcePageIterator", true);

Type: string

Specifies the path to a custom Rust deserialization function for the annotated model property. The value must be a valid Rust path (e.g. "my_crate::serde_helpers::deserialize_foo"). The generated code emits #[serde(deserialize_with = "…")] on the field.

@@clientOption(MyModel.myProperty, "deserialize_with", "my_crate::serde_helpers::deserialize_foo");

Type: string

Specifies the path to a custom Rust serialization function for the annotated model property. The value must be a valid Rust path (e.g. "my_crate::serde_helpers::serialize_foo"). The generated code emits #[serde(serialize_with = "…")] on the field.

@@clientOption(MyModel.myProperty, "serialize_with", "my_crate::serde_helpers::serialize_foo");

Source: Azure.ClientGenerator.Core (from @azure-tools/typespec-client-generator-core)

When applied to a model property, empty string values ("") received from the service are deserialized as None instead of Some(""). Useful for services that use an empty string to represent the absence of a value.

@@deserializeEmptyStringAsNull(MyModel.optionalName);

Source: Azure.ClientGenerator.Core (from @azure-tools/typespec-client-generator-core)

Overrides the auto-generated Rust name for a client or an operation. The provided name is used verbatim, bypassing the emitter’s automatic naming rules (such as prefixing paging methods with list_ or LRO methods with begin_).

@@clientName(MyClient.get_items, "fetch_items", "rust");

The Rust emitter honours the following TypeSpec XML decorators when generating (de)serialization code for XML services:

DecoratorSourceEffect on generated Rust
@encodedName("application/xml", …)TypeSpecSets the XML element name used in #[serde(rename = "…")] for the field.
TypeSpec.Xml.@name@typespec/xmlSets the XML element or attribute name for the field.
TypeSpec.Xml.@attribute@typespec/xmlMarks the field as an XML attribute (#[serde(rename = "@…")]).
TypeSpec.Xml.@unwrapped@typespec/xmlFor array fields, child elements are emitted as direct children (unwrapped list). For string fields, the value is emitted as text content.