{"id":13578543,"url":"https://github.com/dtolnay/inventory","last_synced_at":"2025-04-23T20:53:11.952Z","repository":{"id":41344837,"uuid":"163008374","full_name":"dtolnay/inventory","owner":"dtolnay","description":"Typed distributed plugin registration","archived":false,"fork":false,"pushed_at":"2025-03-03T23:41:05.000Z","size":299,"stargazers_count":1099,"open_issues_count":4,"forks_count":49,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-22T03:00:03.374Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dtolnay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"dtolnay"}},"created_at":"2018-12-24T16:39:22.000Z","updated_at":"2025-04-19T17:08:12.000Z","dependencies_parsed_at":"2023-02-09T21:05:11.133Z","dependency_job_id":"60b14a3c-5b4a-438b-9ec6-71f8c47f6360","html_url":"https://github.com/dtolnay/inventory","commit_stats":{"total_commits":174,"total_committers":9,"mean_commits":"19.333333333333332","dds":0.06321839080459768,"last_synced_commit":"7a2a06e94c87839c07040eee1955a28f1af9f0e1"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Finventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Finventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Finventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Finventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtolnay","download_url":"https://codeload.github.com/dtolnay/inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514765,"owners_count":21443208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T15:01:31.683Z","updated_at":"2025-04-23T20:53:11.933Z","avatar_url":"https://github.com/dtolnay.png","language":"Rust","readme":"## Typed distributed plugin registration\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-dtolnay/inventory-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\" height=\"20\"\u003e](https://github.com/dtolnay/inventory)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/inventory.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/inventory)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-inventory-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\" height=\"20\"\u003e](https://docs.rs/inventory)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/dtolnay/inventory/ci.yml?branch=master\u0026style=for-the-badge\" height=\"20\"\u003e](https://github.com/dtolnay/inventory/actions?query=branch%3Amaster)\n\nThis crate provides a way to set up a plugin registry into which plugins can be\nregistered from any source file linked into your application. There does not\nneed to be a central list of all the plugins.\n\n```toml\n[dependencies]\ninventory = \"0.3\"\n```\n\n*Supports rustc 1.62+*\n\n\u003cbr\u003e\n\n# Examples\n\nSuppose we are writing a command line flags library and want to allow any source\nfile in the application to register command line flags that are relevant to it.\n\nThis is the flag registration style used by [gflags] and is better suited for\nlarge scale development than maintaining a single central list of flags, as the\ncentral list would become an endless source of merge conflicts in an application\ndeveloped simultaneously by thousands of developers.\n\n[gflags]: https://gflags.github.io/gflags/\n\n### Instantiating the plugin registry\n\nLet's use a `struct Flag` as the plugin type, which will contain the short name\nof the flag like `-v`, the full name like `--verbose`, and maybe other\ninformation like argument type and help text. We instantiate a plugin registry\nwith an invocation of `inventory::collect!`.\n\n```rust\npub struct Flag {\n    short: char,\n    name: \u0026'static str,\n    /* ... */\n}\n\nimpl Flag {\n    pub const fn new(short: char, name: \u0026'static str) -\u003e Self {\n        Flag { short, name }\n    }\n}\n\ninventory::collect!(Flag);\n```\n\nThis `collect!` call must be in the same crate that defines the plugin type.\nThis macro does not \"run\" anything so place it outside of any function body.\n\n### Registering plugins\n\nNow any crate with access to the `Flag` type can register flags as a plugin.\nPlugins can be registered by the same crate that declares the plugin type, or by\nany downstream crate.\n\n```rust\ninventory::submit! {\n    Flag::new('v', \"verbose\")\n}\n```\n\nThe `submit!` macro does not \"run\" anything so place it outside of any function\nbody. In particular, note that all `submit!` invocations across all source files\nlinked into your application all take effect simultaneously. A `submit!`\ninvocation is not a statement that needs to be called from `main` in order to\nexecute.\n\n### Iterating over plugins\n\nThe value `inventory::iter::\u003cT\u003e` is an iterator with element type `\u0026'static T`\nthat iterates over all plugins registered of type `T`.\n\n```rust\nfor flag in inventory::iter::\u003cFlag\u003e {\n    println!(\"-{}, --{}\", flag.short, flag.name);\n}\n```\n\nThere is no guarantee about the order that plugins of the same type are visited\nby the iterator. They may be visited in any order.\n\n\u003cbr\u003e\n\n## How it works\n\nInventory is built on runtime initialization functions similar to\n`__attribute__((constructor))` in C, and similar to the [`ctor`] crate. Each\ncall to `inventory::submit!` produces a shim that evaluates the given\nexpression and registers it into a registry of its corresponding type. This\nregistration happens dynamically as part of life-before-main for statically\nlinked elements. Elements brought in by a dynamically loaded library are\nregistered at the time that dlopen occurs.\n\n[`ctor`]: https://github.com/mmastrac/rust-ctor\n\nPlatform support includes Linux, macOS, iOS, FreeBSD, Android, Windows,\nWebAssembly, and a few others. Beyond this, other platforms will simply find\nthat no plugins have been registered.\n\nFor a different approach to plugin registration that *does not* involve\nlife-before-main, see the [`linkme`] crate.\n\n[`linkme`]: https://github.com/dtolnay/linkme\n\n\u003cbr\u003e\n\n#### License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","funding_links":["https://github.com/sponsors/dtolnay"],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Finventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtolnay%2Finventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Finventory/lists"}