Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .claude/skills/rust-style/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,25 @@ let x = a.checked_add(b).ok_or(Error::Overflow)?;

## Casts

No lossy or unchecked casts — use fallible conversions:
**Never use `as` for numeric type conversions** — use fallible conversions with `try_from`:

```rust
// Bad
// Bad - will cause clippy errors
let x = value as u32;
let y = some_usize as u64;

// Good
// Good - use try_from with proper error handling
let x = u32::try_from(value)?;
let y = u64::try_from(some_usize).expect("message explaining why this is safe");
```

Rules:

- Always use `TryFrom`/`try_from` for numeric conversions between different types
- Handle conversion failures explicitly (either with `?` or `expect` with justification)
- The only acceptable use of `expect` is when the conversion is guaranteed to succeed (e.g., `usize` to `u64` on 64-bit platforms)
- Clippy will error on unchecked `as` casts: `cast_possible_truncation`, `cast_possible_wrap`, `cast_sign_loss`

---

## Async / Tokio
Expand Down
Loading
Loading