linkme

Safe, zero-cost distributed slices for Rust, gathered by the linker across your dependency graph.

Library
Cargo
v0.3.37
882stars
Apache-2.0 OR MIT

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity68
Maintenance72
Community48
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture88
Code Quality86
Innovation90
Learning Curve66

linkme is a Rust library that provides distributed slices and distributed statics: collections of static elements that the linker gathers into a contiguous section of the final binary. Elements can be registered from anywhere in the dependency graph, so downstream crates can contribute entries to a slice declared upstream without the declaring crate knowing about them.

The implementation relies on link_section attributes and platform-specific linker support rather than life-before-main or runtime initialization, making it a zero-cost, safe abstraction that resolves entirely at compile and link time. It powers plugin-registration and inventory-style patterns such as test/benchmark collection and command registries.

What You Get

  • The #[distributed_slice] attribute for declaring linker-gathered static slices.
  • Distributed statics for aggregating individual values across crates.
  • A zero-cost abstraction with no life-before-main or runtime initialization.
  • Cross-platform linker support (Linux, macOS, Windows, and more) behind a safe API.

Common Use Cases

  • Automatic registration of tests, benchmarks, or examples across crates.
  • Plugin and command registries where downstream crates contribute entries.
  • Inventory patterns that collect values without a central registration list.

Under The Hood

Architecture - The public crate (src/lib.rs, distributed_slice.rs, private.rs) defines the DistributedSlice type and re-exports the proc-macro from the companion impl/ crate; the macro emits statics annotated with platform-specific #[link_section] names so the linker places them contiguously, and a build.rs probes target support. There is no runtime registration — assembly happens entirely at link time.

Tech Stack - Pure Rust with a proc-macro companion crate (linkme-impl) built on proc-macro2, quote, and syn; a small linker script and build.rs handle platform detection. It has no runtime dependencies beyond the standard library.

Code Quality - The repo carries an integration test suite under tests/ exercising slices and statics across crate boundaries, plus CI across platforms; the code is small, focused, and maintained by dtolnay, whose crates set a high bar for API and documentation quality.

API Design - The surface is intentionally minimal — one attribute macro and a slice type that derefs to &[T] — so usage reads like ordinary Rust; extensive docs.rs documentation and examples make the linker mechanics almost invisible to callers.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search