Skip to content
v0.1.1latest release34 skills2 categories4 sub-categories79 tested scripts157 reference docsContact us

Version History: Trait Features by Rust Version

Reference for rust-trait-design-reviewer · 75 lines

Programming / Rustv1.0.0Updated OCT 21 20267 references7 scripts

Use this to match a suggestion to the project's MSRV (rust-version in Cargo.toml). If the MSRV is older than the version listed, use the "before" column.

Contents

Stabilisations

RustFeatureBefore it
1.26impl Trait in argument and return positionnamed generic parameters; Box<dyn Trait> returns
1.27dyn Trait syntaxbare Trait as a type (deprecated, an error in edition 2021)
1.34TryFrom / TryIntocustom conversion traits or from_str-style constructors
1.41relaxed orphan rule: impl ForeignTrait<LocalType> for ForeignTypenewtype wrappers
1.51const generics (integers, bool, char)macro-generated impls for array sizes
1.62#[derive(Default)] on enums with #[default] on a unit variantmanual impl Default
1.65generic associated types (type Item<'a> where Self: 'a)lending-iterator crates, boxing
1.75async fn and return-position impl Trait in traits (RPITIT)async-trait (boxes every call), associated future types
1.78#[diagnostic::on_unimplemented] for custom "trait not implemented" messages#[rustc_on_unimplemented] (std only)
1.79associated type bounds: T: Iterator<Item: Display>where T::Item: Display
1.81core::error::Error (the Error trait usable in no_std)std-only error types, or crate-specific traits
1.82precise capturing impl Trait + use<'a, T>the Captures<'a> trick
1.85edition 2024; async closures and AsyncFn, AsyncFnMut, AsyncFnOnceFn(..) -> Fut with owned arguments
1.86trait upcasting: &dyn Sub -> &dyn Super coercionan as_super(&self) -> &dyn Super method on the trait

Edition changes that affect traits

EditionChange
2018dyn Trait encouraged (bare trait objects warn); anonymous '_ in impl headers
2021bare trait objects are a hard error; TryFrom, TryInto, FromIterator added to the prelude; disjoint closure captures
2024-> impl Trait (including in traits) captures all in-scope lifetimes by default; impl_trait_overcaptures migration lint; unsafe extern blocks; IntoIterator for Box<[T]>; the gen keyword is reserved

Prelude additions matter for trait design: adding a method named try_from or from_iter to your own trait can become ambiguous once the std trait is in scope everywhere.

Still unstable (do not suggest for stable code)

FeatureStable workaround
Specialization (default fn)separate traits, or a marker trait plus explicit impls
Negative impls (impl !Send for T)a PhantomData<*const ()> field to remove Send/Sync
Associated type defaults (type Out = (); in the trait)document the expected type; add it in a major release
Return type notation (T::method(..): Send)-> impl Future + Send in the trait, or trait_variant
impl Trait in associated types / type aliases (TAIT/ATPIT)name the concrete type, or box it
Trait aliases (trait Svc = Fn() + Send;)a subtrait with a blanket impl: trait Svc: Fn() + Send {} impl<T: Fn() + Send> Svc for T {}
dyn async traits (dyn-compatible async fn)async-trait, or methods returning Pin<Box<dyn Future + Send + '_>>

Check the release notes for the project's toolchain before promising any of these; nightly-only features should never appear in advice for a stable MSRV.

Terminology changes

  • "Object safety" was renamed dyn compatibility in the Rust reference and compiler messages (E0038 now reads "the trait X is not dyn compatible"; older compilers say "cannot be made into an object"). Both refer to the same rules.
  • "RPITIT" = return-position impl Trait in traits; "AFIT" = async fn in traits.

MSRV guidance

  • Libraries: support at least the last few stable releases and state rust-version; CI should build on it (cargo +<msrv> check or cargo msrv verify).
  • async fn in public traits (1.75) is fine for most libraries now; pair it with a Send story.
  • Trait upcasting (1.86) and get_disjoint_mut (1.86) are recent: offer the pre-1.86 workaround if the MSRV is older.
  • Edition 2024 requires Rust 1.85; migrating changes RPIT capture behaviour, so run cargo fix --edition and review use<..> suggestions on public functions.
More in Rust

rust-borrow-checker-error-explainer

Explain and fix Rust borrow-checker, ownership, move and lifetime compiler errors: E0382 use of moved value, E0499 cannot borrow as mutable more than once, E0502 also borrowed as immutable, E0505, E0506, E0503, E0507 cannot move out of index/Rc/reference, E0515 return reference to local, E0597 does not live long enough, E0716 temporary value dropped while borrowed, E0373 closure may outlive (spawn needs move), E0521 borrowed data escapes, E0384, E0596, E0594, E0381, E0713, 'lifetime may not live long enough', RefCell 'already borrowed: BorrowMutError' panics. Ranks fixes from restructuring (split borrows, entry API, split_at_mut, get_disjoint_mut, mem::take, Option::take, indices, thread::scope) down to clone and Rc<RefCell>/Arc<Mutex>; never unsafe. Covers NLL limits (get-or-insert), iterator invalidation, closure captures, self-referential structs. Ships std-only Rust triage tools.

rust-cargo-workspace-designer

Design, review and fix Cargo workspaces: when to split a crate (compile time, boundaries, publishing, proc-macros), crates/* vs apps/ + crates/ layouts, virtual manifest vs root package, members/exclude/default-members, resolver 2 vs 3 (MSRV-aware, edition 2024), [workspace.package] and [workspace.dependencies] inheritance, [workspace.lints], root-only profiles (lto, codegen-units), additive features with dep: and weak ?/ syntax, feature unification pitfalls, internal path + version deps, publish = false, Cargo.lock and MSRV policy, xtask, CI with --locked, nextest, rust-cache, sccache, cargo-hack/deny/machete/udeps/semver-checks, and cargo build --timings. Ships a workspace auditor and crate-graph tool.

rust-error-handling-thiserror-anyhow-designer

Design and review Rust error handling with thiserror 2 and anyhow 1: library vs application split, typed error enums with #[from], #[source], #[error(transparent)] and #[non_exhaustive], ErrorKind patterns, context via .context()/.with_context(), bail!/ensure!, source() chains, {:#} and {:?} reports, RUST_BACKTRACE/RUST_LIB_BACKTRACE, Box<dyn Error + Send + Sync>, main -> anyhow::Result or ExitCode, unwrap/expect/panic policy, Option to Result, collecting iterators of Results, axum IntoResponse mapping, retryable errors, tracing, async Send bounds, testing with matches! and downcast_ref, no_std core::error::Error, and snafu, eyre/color-eyre, miette, error-stack.

rust-lifetime-annotation-advisor

Decide when Rust lifetime annotations are needed and which ones: the three elision rules, structs holding references (struct Parser<'a>), owned vs borrowed (String, &str, Cow<'a, str>, Arc<str>), one vs several lifetimes, 'a: 'b bounds, T: 'static misconceptions, Box<dyn Trait + 'a> default object lifetimes, impl Trait + '_ and edition 2024 capture rules with use<..>, variance and PhantomData, HRTB for<'a> Fn(&'a T), GATs and lending iterators, async fn and tokio::spawn 'static, self-referential structs (ouroboros, self_cell, indices, arenas), Rc/Arc to escape lifetime soup. Ships std-only Rust checkers for redundant, missing, unused and over-restrictive lifetimes.

rust-tokio-async-service-builder

Build and review production async Rust services on Tokio 1.x and axum 0.8: runtime choice (#[tokio::main] multi_thread vs current_thread, Builder), axum routing with /{id} paths, State, extractors, IntoResponse error types, axum::serve with_graceful_shutdown, tower/tower-http middleware (TraceLayer, TimeoutLayer, CorsLayer, ConcurrencyLimitLayer, RequestBodyLimitLayer), Arc<AppState>, std vs tokio Mutex, JoinSet, TaskTracker, CancellationToken, select! cancel safety, bounded mpsc, oneshot, broadcast, watch, actors, Semaphore, timeouts, retries, spawn_blocking, sqlx PgPool, reqwest Client reuse, tracing, tests with start_paused and oneshot, Dockerfile. Fixes 'future cannot be sent between threads safely', E0373, Rc or MutexGuard held across await, 'Cannot start a runtime from within a runtime', 'Path segments must not start with :'. Ships std-only Rust scanners and a compiling axum 0.8 scaffold.

rust-unsafe-block-auditor

Audit unsafe Rust for soundness: inventory every unsafe block, unsafe fn, unsafe impl/trait, extern block and unsafe attribute, check // SAFETY: comments and # Safety docs, and classify each as sound, needs-justification or likely UB, proposing safe alternatives first. Covers the five unsafe superpowers, aliasing (Stacked/Tree Borrows), invalid values, MaybeUninit vs mem::zeroed/uninitialized, transmute, slice::from_raw_parts, Vec::set_len/from_raw_parts, get_unchecked, CString::as_ptr dangling, unsafe impl Send/Sync, Pin projection, FFI (extern "C", repr(C), C-unwind, Box::into_raw/from_raw), strict provenance, static mut and &raw, edition 2024 (unsafe extern, #[unsafe(no_mangle)], unsafe_op_in_unsafe_fn, env::set_var), Miri, sanitizers, cargo-fuzz, loom, cargo-geiger and clippy safety lints.