Skip to content

Commit b00bad9

Browse files
chore(rust): add CLAUDE.md for rust generator (#9859)
chore(rust): add claude.md for rust generator
1 parent d34826d commit b00bad9

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

generators/rust/CLAUDE.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Rust Generator
2+
3+
This file provides guidance for Claude Code when working with the Rust generator.
4+
5+
## Rust-Specific Requirements
6+
7+
- **Framework compatibility**: Generated code targets modern Rust (2021 edition+) with tokio async runtime
8+
- **Dependencies**: Minimize dependencies; prefer serde for serialization, reqwest for HTTP
9+
- **Naming conventions**:
10+
* Crate names and modules: snake_case
11+
* Structs, enums, traits: PascalCase
12+
* Functions, methods, variables: snake_case
13+
* Constants: SCREAMING_SNAKE_CASE
14+
- **Async patterns**: Use async/await with tokio runtime for all I/O operations
15+
- **Error handling**: Use Result<T, E> with custom error types
16+
- **Formatting**: All code must pass `rustfmt` and `cargo clippy`
17+
18+
## Key Directories
19+
20+
### Rust Generator (generators/rust/)
21+
- `base/` - Base generator infrastructure (CLI, context, project management)
22+
- `codegen/` - Rust AST builder and code generation primitives
23+
- `sdk/` - Full SDK generator with HTTP client
24+
- `model/` - Rust type generation (structs, enums, unions)
25+
- `dynamic-snippets/` - Code example generation
26+
27+
## Key Architectural Patterns
28+
29+
**Five-Package Structure**:
30+
1. **base/** - Shared infrastructure (`AbstractRustGeneratorCli`, `RustProject`, `RustFilenameRegistry`)
31+
2. **codegen/** - AST builder (`Writer`, `Struct`, `Enum`, `Method`, etc.)
32+
3. **model/** - Type generation (structs, enums, unions, aliases)
33+
4. **sdk/** - Full SDK with HTTP client, pagination, error handling
34+
5. **dynamic-snippets/** - Code example generation
35+
36+
**Filename Collision Resolution**: Priority-based registration system appends `_type` suffix to resolve conflicts (e.g., `user.rs``user_type.rs`). Don't bypass `RustFilenameRegistry`.
37+
38+
**Template Variables**: Static files in `/base/src/asIs/` use placeholders like `{{PACKAGE_NAME}}`, `{{PACKAGE_VERSION}}` replaced by `RustProject.replaceTemplateVariables()`.
39+
40+
**Dual-Generator Pattern**: SDK composes model generator via `generateModels({ context: sdkContext.toModelGeneratorContext() })` for consistency.
41+
42+
## Development
43+
44+
```bash
45+
pnpm install
46+
pnpm --filter @fern-api/rust-sdk compile
47+
pnpm --filter @fern-api/rust-model compile
48+
pnpm --filter @fern-api/rust-sdk dist:cli # Build Docker CLI
49+
pnpm --filter @fern-api/rust-model dist:cli # Build Docker CLI
50+
```
51+
52+
### Configuration Options
53+
54+
Configuration schema: `generators/rust/codegen/src/custom-config/RustSdkCustomConfigSchema.ts` and `RustModelCustomConfigSchema.ts`
55+
56+
## Testing
57+
58+
```bash
59+
# From repository root
60+
pnpm seed test --generator rust-sdk --fixture <fixture-name> --skip-scripts
61+
pnpm seed test --generator rust-model --fixture <fixture-name> --skip-scripts
62+
```
63+
64+
When working with the Rust generator:
65+
- Verify generated code compiles: `cd seed/rust-sdk/<fixture> && cargo build`
66+
- Run generated tests: `cargo test`
67+
- Validate formatting: `cargo fmt --check && cargo clippy`
68+
- Check AST node tests with vitest snapshots: `pnpm test:update --filter @fern-api/rust-codegen`

0 commit comments

Comments
 (0)