> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJmMzJlMTU4NC1lYjI3LTQ1ZjgtYjNkMC1lNWUwMWVmM2MxYjQiLCJleHAiOjE3Nzg0MDIxODAsImlhdCI6MTc3ODQwMTg4MH0.YG6Z1UfwXaE4UzOJCiepHqPK5LPSeu6rfF0FgQjpixU
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# Rust 配置

> Fern Rust SDK 的配置选项。

您可以在 `generators.yml` 中自定义 Rust SDK 生成器的行为：

```yaml {6-15} title="generators.yml"
groups:
  rust-sdk:
    generators:
      - name: fernapi/fern-rust-sdk
        version: 0.35.0
        config:
          clientClassName: YourClientName
          crateName: your-crate-name
          crateVersion: "1.0.0"
          dateTimeType: "offset"
          environmentEnumName: YourEnvironment
          enableWireTests: true
```

<ParamField path="clientClassName" type="string" required={false} toc={true}>
  生成的客户端结构体的名称。这允许您自定义用户在使用您的 SDK 时将实例化的结构体名称。
</ParamField>

<ParamField path="crateName" type="string" required={false} toc={true}>
  生成的 Rust crate 的名称。这在 `Cargo.toml` 中使用，并决定用户如何将您的 SDK 添加为依赖项。
</ParamField>

<ParamField path="crateVersion" type="string" required={false} toc={true}>
  生成的 crate 的版本。这在 `Cargo.toml` 中使用，用于发布到 crates.io。
</ParamField>

<ParamField path="dateTimeType" type="'offset' | 'utc'" default="offset" required={false} toc={true}>
  确定如何处理时区信息：

  * `offset`：使用 `DateTime<FixedOffset>` 来保留 API 响应中的原始时区
  * `utc`：使用 `DateTime<Utc>` 将所有日期时间标准化为 UTC，无论其原始时区如何

  两个选项都接受任何日期时间格式，如果日期时间字符串中没有提供时区，则假定为 UTC。
</ParamField>

<ParamField path="environmentEnumName" type="string" required={false} toc={true}>
  生成的环境枚举的名称。这允许您自定义定义 API 环境（如生产、预发布、开发）的枚举名称。
</ParamField>

<ParamField path="enableWebsockets" type="boolean" default="false" required={false} toc={true}>
  启用时，为具有 WebSocket 通道的 API 生成 WebSocket 客户端代码。WebSocket 通道可通过根客户端的连接器结构体访问（例如 `client.realtime.connect(...)`）。
</ParamField>

<ParamField path="enableWireTests" type="boolean" default="false" required={false} toc={true}>
  启用时，生成[模拟服务器（wire）测试](/learn/sdks/deep-dives/testing#mock-server-tests)来验证 SDK 是否发送正确的 HTTP 请求并按照 API 规范正确处理响应。
</ParamField>

<ParamField path="generateExamples" type="boolean" default="true" required={false} toc={true}>
  启用时，在 README 和参考文档中生成代码示例。
</ParamField>

### 包元数据

配置发布到 crates.io 的元数据：

```yaml title="generators.yml"
config:
  packageDescription: "SDK for the Plant Store API"
  packageLicense: "MIT"
  packageRepository: "https://github.com/your-org/your-sdk"
  packageDocumentation: "https://docs.example.com"
```

<ParamField path="packageDescription" type="string" required={false} toc={true}>
  crates.io 上 crate 的描述。这会出现在 crate 的元数据和搜索结果中。
</ParamField>

<ParamField path="packageLicense" type="string" required={false} toc={true}>
  crate 的许可证标识符（例如 "MIT"、"Apache-2.0"）。
</ParamField>

<ParamField path="packageLicenseFile" type="string" required={false} toc={true}>
  自定义许可证文件的路径（例如 `LICENSE.md`）。设置时，在 `Cargo.toml` 中使用 `license-file` 而不是 `license`。当您的许可证不是标准的软件包数据交换（SPDX）标识符时，这很有用。
</ParamField>

<ParamField path="packageRepository" type="string" required={false} toc={true}>
  crate 源代码仓库的 URL。
</ParamField>

<ParamField path="packageDocumentation" type="string" required={false} toc={true}>
  crate 文档的 URL。
</ParamField>

### 依赖项

为生成的 SDK 添加自定义依赖项：

```yaml title="generators.yml"
config:
  extraDependencies:
    tokio: "1.0"
    serde_json: "1.0"
  extraDevDependencies:
    mockall: "0.11"
```

<ParamField path="extraDependencies" type="object" required={false} toc={true}>
  要包含在生成的 `Cargo.toml` 中的额外依赖项。指定为 crate 名称到版本要求的映射。您还可以指定具有功能和默认功能的完整依赖项规范：

  ```yaml title="generators.yml"
  config:
    extraDependencies:
      reqwest:
        version: "0.12"
        defaultFeatures: true
  ```

  ```yaml title="generators.yml"
  config:
    extraDependencies:
      reqwest:
        version: "0.12"
        features: ["rustls-tls"]
  ```
</ParamField>

<ParamField path="extraDevDependencies" type="object" required={false} toc={true}>
  要包含在生成的 `Cargo.toml` 中的额外开发依赖项。这些仅在开发和测试期间使用。
</ParamField>