rust-pitfalls
/rust-pitfalls
Wskazuje pułapki w Rust, które się kompilują, przechodzą clippy i zwykłe testy, a zawodzą dopiero na brzegu lub przy zamykaniu programu.
- Autor
- eduardoghi ↗
- Repozytorium
- dev-skills ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 11.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 11.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Wskazuje pułapki w Rust, które się kompilują, przechodzą clippy i zwykłe testy, a zawodzą dopiero na brzegu lub przy zamykaniu programu.
Oryginalny opis (EN)
Mistakes in Rust that compile, pass clippy and the usual tests, and fail on an edge or at exit. Use when writing or reviewing Rust.
Jak działa
- thensome works out its value first
- Threads still using a driver when the process ends
Podgląd SKILL.md
---
name: rust-pitfalls
description: Mistakes in Rust that compile, pass clippy and the usual tests, and fail on an edge or at exit. Use when writing or reviewing Rust.
paths:
- "**/*.rs"
---
# Rust pitfalls
## `then_some` works out its value first
`condition.then_some(value)` reads like the value is only made when the condition holds, but the
argument is evaluated before the call, every time. With an index at its largest value,
```rust
(index < MAX).then_some(index + 1)
```
overflows and panics in a debug build even though the check fails, and wraps around in release.
Use `then`, whose closure only runs when the condition holds:
```rust
(index < MAX).then(|| index + 1)
```
A test with the edge value, such as `u32::MAX`, catches it.
## Threads still using a driver when the process ends
Returning from `main` calls `exit`, which runs the cleanup that C libraries registered, the
graphics driver's among them. A thread that is still tearing down something on that driver, such
as a GStreamer pipeline with a hardware decoder, races that cleanup, and the process aborts with a
double free on the way out. Dropping a handle that only tells the thread to stop isn't enough.
Count the threads, wait for them with a deadline after the work that stops them, and if one is
still running past it, end with `_exit` from the C runtime, which skips the cleanup:
```rust
extern "C" {
fn _exit(code: i32) -> !;
}
```
Save anything that has to persist before that point, since `_exit` runs no destructors.
Wersje
W bazie nie ma innych skilli o nazwie rust-pitfalls.
Migawka bazy z 13.11.2026 · wersja paczki 1ea6e94d889e (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 95cpp-pitfalls
Wskazuje pułapki C++, które się kompilują i przechodzą przegląd, a zawieszają się lub zawodzą dopiero na ścieżce błędu lub przy wyjściu. - 95qt-pitfalls
Wskazuje błędy w QML, które się kompilują i przechodzą qmllint, lecz zawodzą dopiero na ekranie. - 100clippy-configuration
Konfiguruje Clippy w projektach Rust przez plik TOML, grupy lintów, atrybuty i ustawienia workspace. - 100rust-pro
Pomaga pisać i przeglądać kod Rust, w tym projekty Cargo, zmiany własności i pożyczek, async, traity, błędy, uwagi clippy i testy. - 100clippy-custom
Pomaga tworzyć własne lints Clippy, implementować przebiegi lintów i wnosić wkład do Clippy dla standardów kodu Rust. - 100rust-development
Obsługuje pełny toolchain Rust: cargo, rustfmt, clippy i kompilację do WASM, przy budowie, testach i błędach kompilacji.