rust-patterns
Idiomatic Rust patterns and best practices for readable, safe, maintainable Rust: ownership, borrowing, API design, enums/traits, error handling, iterators, concurrency, dynamic dispatch/plugins, and low-level/offensive patterns. Use when writing or reviewing `.rs` code, refactoring crates, porting
v2026.11.13-21cd5683 установки+3 за 7 дней39 ЗвездыMITсинхронизировано 10 часов назад
Установка
Ещё нет NotHoly CLI? Сначала установите её.
$ curl -fsSL https://notholy.com/install.sh | sh$ notholy skills install aeondave/rust-patternsПишет в ~/.notholy/skills после проверки подписи и SHA-256.
ПодписьПодписано, ed25519
Пакет029753b6…5e07b41e
029753b6499e…18f45e07b41e12 файлов · 27.0 KBПроверкаСредний3 замечания
- injection.no_confirmationreferences/language.md:76
- injection.no_confirmationreferences/security-review.md:62
- Ссылки на внешние домены
Источникgithub.com/AeonDave/malskill/tree/main/coding/rust-patterns@21cd568
Эта запись еще не переведена на русский, поэтому показан текст на другом языке: English.
На странице
This skill is for day-to-day idiomatic Rust: clear ownership, small APIs, and code that feels native to the language instead of a direct port from somewhere else.
If the task is primarily profiling/benchmarking, use rust-performance. If the task is primarily test design or test repair, use rust-testing.
When to activate
- Writing or refactoring
.rsmodules, libraries, CLIs, or services - Reviewing Rust PRs for ownership, borrowing, API shape, and common footguns
- Porting code from C/C++/Go/Python into idiomatic Rust
- Improving error handling, trait design, iterators, module boundaries, concurrency, or docs
- Choosing a dispatch/plugin mechanism, or building low-level/offensive Rust with
unsafe, FFI, or RE-resistant builds
Core rules (high signal)
- Make ownership obvious in signatures: borrow by default, own when storing or crossing boundaries.
- Model the domain with enums, newtypes, and builders instead of flag soup and loosely related primitives.
- Use
Resultfor fallible work; reservepanic!,unwrap, andexpectfor tests or truly impossible states. - Prefer iterators and pattern matching when they make intent clearer; do not turn readable logic into adapter golf.
- Keep public APIs small and deliberate; re-export intentionally and hide implementation details.
- Run
cargo fmtandcargo clippy; style should not be negotiated by hand. - Treat crate
editionas a semantic gate (capture rules, drop order,unsafeattributes,set_var). Do not assume the installed rustc edition.
Outcome expectations
- Public APIs make ownership and failure behavior obvious at call sites.
- Domain modeling uses enums/newtypes/builders instead of ad-hoc primitives.
- Borrowing is preferred where practical; cloning is intentional and justified.
- Tooling (
fmt,clippy,test, docs) is part of the definition of done.
Recommended workflow
- Define API boundaries and ownership semantics in function signatures.
- Model states/errors with enums and typed results before implementing details.
- Implement with small focused functions and explicit visibility boundaries.
- Run
cargo fmt,cargo clippy, andcargo testbefore review. - Review for accidental clones, over-broad traits, and panic-prone paths.
Quick review checklist
- No
clone()used only to silence the borrow checker unless the clone is cheap and intentional - Inputs borrow where possible (
&str,&[T],&Path,impl AsRef<Path>) instead of forcing ownership - Error paths preserve context and use
?; production code does not rely on strayunwrap - Enums beat boolean parameters; newtypes beat domain-significant bare integers/strings
- Traits are small and consumer-oriented; generic signatures are useful, not ornamental
- Module visibility is tidy (
pub,pub(crate), private helpers, selectivepub use)
Common anti-patterns to reject
clone()used only to “make borrow checker errors go away”- Public APIs that force ownership when a borrow would do
- Boolean/flag parameter combinations that should be enums
- Library code depending on routine
unwrap/expectin operational paths - Large traits that couple unrelated behavior and block evolution
Platform and FFI boundaries
- Keep platform-specific modules small and make them return the same public types as the shared path.
- Prefer adapting one unstable primitive over forking a full protocol or workflow. Example shape:
connect_with_timeout(...) -> io::Result<TcpStream>can usestd::netnormally and a Windows FFI helper only in a constrained build mode. - Use feature gates to remove incompatible definitions, not just unreachable call sites, when signatures or imports differ by build mode.
- After adding Windows FFI bindings or
windows-sysfeatures, run a real target build;cargo checkcan pass before the linker sees missing imports or feature flags. - For raw-pointer,
unsafe, uninitialized-memory, or ABI work, keepunsafeminimal behind a safe API and document invariants; loadreferences/unsafe-and-ffi.md. - When auditing untrusted-input handling,
unsafesoundness, or a dependency tree for security bugs, loadreferences/security-review.md.
Resources
Load on demand:
references/language.md— load when using Edition 2024,async fn/ RPITIT in traits,use<>capture, async closures /AsyncFn, let chains, if-let guards,#[expect], or edition-gatedunsafeattributesreferences/ownership-and-borrowing.md— use when signatures, lifetimes, moves, or borrow-checker friction are centralreferences/api-design.md— use when shaping public types, traits, builders, and module boundariesreferences/errors-and-results.md— use when designing recoverable errors or cleaning up panic-prone codereferences/collections-and-iterators.md— use when choosing collections or refactoring loops into clearer iterator codereferences/tooling-and-docs.md— use when reviewing formatting, clippy, rustdoc, features,edition/rust-version, or crate hygienereferences/concurrency.md— use when choosing shared-state, channel, scoped threads,OnceLock/LazyLock, poison, or async callback patternsreferences/dynamic-dispatch-and-plugins.md— use when choosingdynvs generics vs enum dispatch, building plugin registries, loading code at runtime, or structuring command dispatchersreferences/unsafe-and-ffi.md— use forunsafeblocks, raw pointers, provenance, uninitialized memory,repr(C)/ABI, or C FFI boundariesreferences/offensive-lowlevel.md— use for RE-resistance, string obfuscation, memory protection,no_stdentry points, inline asm/syscalls, or malware-style modular architecturereferences/security-review.md— use when auditing Rust for security bugs: untrusted input, panics/DoS, integer overflow, secrets, or supply-chain risk
Файлы этой версии
references/1158.4 KB
- api-design.md2.2 KB
- collections-and-iterators.md2.5 KB
- concurrency.md7.1 KB
- dynamic-dispatch-and-plugins.md10.6 KB
- errors-and-results.md2.2 KB
- language.md8.8 KB
- offensive-lowlevel.md6.4 KB
- ownership-and-borrowing.md1.7 KB
- security-review.md6.2 KB
- tooling-and-docs.md2.0 KB
- unsafe-and-ffi.md8.7 KB
- SKILL.md6.6 KB
Права
| Право | Заявлено | Найдено проверкой |
|---|---|---|
| Читает файлы | Нет | Нет |
| Пишет файлы | Да | Да |
| Выполняет команды shell | Да | Да |
| Ходит в сеть | Да | Да |
| Использует коннекторы | Нет | Нет |
| Управляет браузером | Нет | Нет |
Замечания проверки
Проверено 13 нояб. 2026 г.
- СредняяPrompt injection · injection.no_confirmationreferences/language.md:76
- СредняяPrompt injection · injection.no_confirmationreferences/security-review.md:62
- ИнфоСсылка · Ссылки на внешние домены
Чистая проверка снижает риск, но не доказывает, что пакет безопасен. Читайте то, что ставите.
| Версия | Опубликована | Коммит | SHA-256 | Подпись | Изменение прав |
|---|---|---|---|---|---|
| v2026.11.13-21cd568 | 13 нояб. 2026 г. | 21cd568 | 029753b6 | Подписана | – |
Ещё от AeonDave
Всё от этого издателяЕще в категории «API, SaaS и идентификация»
Вся категория- testing-for-sensitive-data-exposuremukul975/testing-for-sensitive-data-exposure5
- performing-jwt-none-algorithm-attackmukul975/performing-jwt-none-algorithm-attack5
- sharp-edgestrailofbits/sharp-edges4
- hydraaeondave/hydra4
- implementing-google-workspace-admin-securitymukul975/implementing-google-workspace-admin-security4
- implementing-api-security-posture-managementmukul975/implementing-api-security-posture-management4
Спрашивайте обо всём, что позволяет ваш скоуп.
Создайте аккаунт, пополните баланс и задайте первый вопрос в чате или в терминале.
- 1/3
Создайте аккаунт
Личный или для компании. Позже можно перейти на аккаунт компании без потери баланса и ключей.
ЛичныйКомпания - 2/3
Пополните баланс
Картой. Оплата за токены, без подписки.
$5.00минимальное пополнение - 3/3
Спрашивайте
В чате, или установите CLI и выполните notholy login в терминале.
$ notholy login