Retour au classement

mmastrac/linktime

Rust

Link-time initialization, destruction, scattered data collection macros for Rust

rustmacrosconstructordylibctordtorlink-sectionlinktime
Croissance des étoiles
Étoiles
1k
Forks
78
Croissance hebdomadaire
Issues
9
5001k
déc. 2018juin 2021janv. 2024juil. 2026
Artefactscrates.iocargo add linktime
README

linktime

Cross-platform libraries for link-time initialization, finalization and collection in Rust.

GitHub Crates.io License Build Status

crate docs version
linktime Convenience crate for ctor, dtor and link-section docs.rs crates.io
ctor Module initialization functions before main docs.rs crates.io
dtor Module shutdown functions before main docs.rs crates.io
link-section Linker-managed typed (slices) and untyped sections docs.rs crates.io
scattered-collect Linker-managed collections: slices, sorted slices, maps docs.rs crates.io

Crates

The linktime project comprises three crates, and the top-level linktime crate aggregates them all.

Pick-and-choose, or import the top-level crate to get all three.

ctor

Module initialization functions for Rust (like __attribute__((constructor)) in C/C++).

Run code before main to initialize data, external resources, or other state.

[dependencies]
linktime = { version = "...", features = ["ctor"] }  # note: already enabled by default
# or
ctor = "..."
use linktime::ctor; // or ctor::ctor
use libc_print::*;

#[ctor(unsafe)]
fn foo() {
    libc_println!("Life before main!");
}

dtor

Module shutdown functions for Rust (like __attribute__((destructor))).

Run code after main to clean up resources, or perform other final operations.

[dependencies]
linktime = { version = "...", features = ["dtor"] }  # note: already enabled by default
# or
dtor = "..."
use linktime::dtor; // or dtor::dtor
use libc_print::*;

#[dtor(unsafe)]
fn foo() {
    libc_println!("Life after main!");
}

Typed and untyped link section support for Rust.

Collect related items from an entire linked binary into a single link section.

[dependencies]
linktime = { version = "...", features = ["link-section"] }  # note: already enabled by default
# or
link-section = "..."
use linktime::link_section::{section, in_section, TypedSection};
use linktime::ctor;
use libc_print::*;

#[section(typed)]
static FOO: TypedSection<fn()>;

#[in_section(FOO)]
fn foo() {
    libc_println!("Hello, world!");
}

#[ctor(unsafe)]
fn print_numbers() {
    for f in FOO {
        f();
    }
}

scattered-collect

A crate for defining zero-allocation,linker-managed scattered collections in Rust.

  • ScatteredIterable: A collection of items that are available only via
  • ScatteredSlice: A collection of sized items that collected into a slice in an arbitrary order.
  • ScatteredSortedSlice: A collection of items that are available via slice, in sorted order.
  • ScatteredReferencedSlice: A collection of items collected into a slice (link order).
  • ScatteredSortedReferencedSlice: A collection of sized items that are available both via sorted slice and via reference at the declaration site.
  • ScatteredMap: A collection of key-value pairs that are available via slice, as well as indexed by key.
use scattered_collect::{gather, scatter, slice::ScatteredSlice};

#[gather]
static SLICE_PLUGINS: ScatteredSlice<&'static str>;

#[scatter(SLICE_PLUGINS)]
const _: &'static str = "json";

#[scatter(SLICE_PLUGINS)]
const _: &'static str = "yaml";

fn main() {
    assert_eq!(SLICE_PLUGINS.len(), 2);
    assert!(SLICE_PLUGINS.contains(&"json"));
}

Contributing

Contributions are welcome!

License

These projects are dual-licensed under the Apache License, Version 2.0 and the MIT License.

Dépôts similaires
farion1231/cc-switch

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

Rustcrates.ioMIT Licenseai-toolsclaude-code
ccswitch.io
119.8k8k
rustdesk/rustdesk

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Rustcrates.ioGNU Affero General Public License v3.0remote-controlremote-desktop
rustdesk.com
118.6k18.1k
rust-lang/rust

Empowering everyone to build reliable and efficient software.

Rustcrates.ioApache License 2.0rustcompiler
rust-lang.org
114.8k15.4k
tauri-apps/tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.

Rustcrates.ioApache License 2.0rustwebview
tauri.app
109.3k3.8k
denoland/deno

A modern runtime for JavaScript and TypeScript.

Rustcrates.ioMIT Licensedenotypescript
deno.com
107.8k6.2k
oven-sh/bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Rustcrates.ioOtherbunbundler
bun.com
95k4.9k
unionlabs/union

The trust-minimized, zero-knowledge bridging protocol, designed for censorship resistance, extremely high security, and usage in decentralized finance.

Rustcrates.ioApache License 2.0blockchaincosmos
union.build
73.9k3.9k
rtk-ai/rtk

CLI proxy that reduces LLM token consumption by 60-90% on common dev commands. Single Rust binary, zero dependencies

Rustcrates.ioApache License 2.0agentic-codingai-coding
rtk-ai.app
72.4k4.5k
toeverything/AFFiNE

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

TypeScriptnpmOthereditorcrdt
affine.pro
70.7k5.1k
openinterpreter/openinterpreter

A coding agent for open models like Kimi K3

Rustcrates.ioApache License 2.0coding-agentdeepseek
openinterpreter.com
67.1k5.8k
BurntSushi/ripgrep

ripgrep recursively searches directories for a regex pattern while respecting your gitignore

Rustcrates.ioThe Unlicenseripgreprecursively-search
66.4k2.7k
alacritty/alacritty

A cross-platform, OpenGL terminal emulator.

Rustcrates.ioApache License 2.0terminal-emulatorsopengl
alacritty.org
65k3.5k