ctor

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

Latest version: 1.0.7 registry icon
Maintenance score
100
Safety score
100
Popularity score
40
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
1.0.7 0 0 0 0 0
1.0.6 0 0 0 0 0
1.0.5 0 0 0 0 0
1.0.4 0 0 0 0 0
1.0.3 0 0 0 0 0
1.0.2 0 0 0 0 0
1.0.1 0 0 0 0 0
1.0.0 0 0 0 0 0
0.13.1 0 0 0 0 0
0.13.0 0 0 0 0 0
0.12.0 0 0 0 0 0
0.11.1 0 0 0 0 0
0.11.0 0 0 0 0 0
0.10.1 0 0 0 0 0
0.10.0 0 0 0 0 0
0.9.1 0 0 0 0 0
0.9.0 0 0 0 0 0
0.8.0 0 0 0 0 0
0.7.0 0 0 0 0 0
0.6.3 0 0 0 0 0
0.6.2 0 0 0 0 0
0.6.1 0 0 0 0 0
0.6.0 0 0 0 0 0
0.5.0 0 0 0 0 0
0.4.3 0 0 0 0 0
0.4.2 0 0 0 0 0
0.4.1 0 0 0 0 0
0.4.0 0 0 0 0 0
0.3.6 0 0 0 0 0
0.3.5 0 0 0 0 0
0.3.4 0 0 0 0 0
0.3.3 0 0 0 0 0
0.3.2 0 0 0 0 0
0.3.1 0 0 0 0 0
0.3.0 0 0 0 0 0
0.2.9 0 0 0 0 0
0.2.8 0 0 0 0 0
0.2.7 0 0 0 0 0
0.2.6 0 0 0 0 0
0.2.5 0 0 0 0 0
0.2.4 0 0 0 0 0
0.2.3 0 0 0 0 0
0.2.2 0 0 0 0 0
0.2.1 0 0 0 0 0
0.2.0 0 0 0 0 0
0.1.26 0 0 0 0 0
0.1.25 0 0 0 0 0
0.1.24 0 0 0 0 0
0.1.23 0 0 0 0 0
0.1.22 0 0 0 0 0
0.1.21 0 0 0 0 0
0.1.20 0 0 0 0 0
0.1.19 0 0 0 0 0
0.1.18 0 0 0 0 0
0.1.17 0 0 0 0 0
0.1.16 0 0 0 0 0
0.1.15 0 0 0 0 0
0.1.14 0 0 0 0 0
0.1.13 0 0 0 0 0
0.1.12 0 0 0 0 0
0.1.11 0 0 0 0 0
0.1.10 0 0 0 0 0
0.1.9 0 0 0 0 0
0.1.8 0 0 0 0 0
0.1.7 0 0 0 0 0
0.1.6 0 0 0 0 0
0.1.5 0 0 0 0 0
0.1.4 0 0 0 0 0
0.1.3 0 0 0 0 0
0.1.2 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0

Stability
Latest release:

1.0.7 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant


Apache-2.0   -   Apache License 2.0

Not a wildcard

Not proprietary

OSI Compliant



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.

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!");
}

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();
    }
}

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.