inventory-0.3.21/.cargo_vcs_info.json0000644000000001360000000000100131540ustar { "git": { "sha1": "c8310fa1b9d6dc4b41f74dea98cd01d5fd490f72" }, "path_in_vcs": "" }inventory-0.3.21/.github/FUNDING.yml000064400000000000000000000000201046102023000151110ustar 00000000000000github: dtolnay inventory-0.3.21/.github/workflows/ci.yml000064400000000000000000000053241046102023000164630ustar 00000000000000name: CI on: push: pull_request: workflow_dispatch: schedule: [cron: "40 1 * * *"] permissions: contents: read env: RUSTFLAGS: -Dwarnings jobs: pre_ci: uses: dtolnay/.github/.github/workflows/pre_ci.yml@master test: name: ${{matrix.name || format('Rust {0}', matrix.rust)}} needs: pre_ci if: needs.pre_ci.outputs.continue runs-on: ${{matrix.os}}-latest strategy: fail-fast: false matrix: rust: [nightly, beta, stable, 1.70.0] os: [ubuntu] include: - name: macOS os: macos rust: nightly - name: Windows (gnu) os: windows rust: nightly-x86_64-pc-windows-gnu - name: Windows (msvc) os: windows rust: nightly-x86_64-pc-windows-msvc timeout-minutes: 45 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} - name: Enable type layout randomization run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV if: startsWith(matrix.rust, 'nightly') shell: bash - name: Ignore Windows linker warning run: echo RUSTFLAGS=${RUSTFLAGS}\ -Alinker_messages >> $GITHUB_ENV if: matrix.rust == 'nightly-x86_64-pc-windows-gnu' shell: bash - run: cargo test - uses: actions/upload-artifact@v4 if: matrix.os == 'ubuntu' && matrix.rust == 'nightly' && always() with: name: Cargo.lock path: Cargo.lock continue-on-error: true msrv: name: Rust 1.62.0 needs: pre_ci if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest timeout-minutes: 45 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.62.0 - run: cargo check doc: name: Documentation needs: pre_ci if: needs.pre_ci.outputs.continue runs-on: ubuntu-latest timeout-minutes: 45 env: RUSTDOCFLAGS: -Dwarnings steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - uses: dtolnay/install@cargo-docs-rs - run: cargo docs-rs clippy: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy -- -Dclippy::all -Dclippy::pedantic outdated: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' timeout-minutes: 45 steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - uses: dtolnay/install@cargo-outdated - run: cargo outdated --exit-code 1 inventory-0.3.21/.gitignore000064400000000000000000000000251046102023000137310ustar 00000000000000/target/ /Cargo.lock inventory-0.3.21/Cargo.lock0000644000000204160000000000100111320ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "dissimilar" version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8975ffdaa0ef3661bfe02dbdcc06c9f829dfafe6a3c474de366a8d5e44276921" [[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "glob" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" [[package]] name = "indexmap" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "inventory" version = "0.3.21" dependencies = [ "rustversion", "trybuild", ] [[package]] name = "itoa" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "memchr" version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "proc-macro2" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "rustversion" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "serde" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "serde_spanned" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40734c41988f7306bb04f0ecf60ec0f3f1caa34290e4e8ea471dcd3346483b83" dependencies = [ "serde", ] [[package]] name = "syn" version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "target-triple" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ac9aa371f599d22256307c24a9d748c041e548cbf599f35d890f9d365361790" [[package]] name = "termcolor" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "toml" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75129e1dc5000bfbaa9fee9d1b21f974f9fbad9daec557a521ee6e080825f6e8" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", "toml_parser", "toml_writer", "winnow", ] [[package]] name = "toml_datetime" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bade1c3e902f58d73d3f294cd7f20391c1cb2fbcb643b73566bc773971df91e3" dependencies = [ "serde", ] [[package]] name = "toml_parser" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b551886f449aa90d4fe2bdaa9f4a2577ad2dde302c61ecf262d80b116db95c10" dependencies = [ "winnow", ] [[package]] name = "toml_writer" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcc842091f2def52017664b53082ecbbeb5c7731092bad69d2c63050401dfd64" [[package]] name = "trybuild" version = "1.0.110" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32e257d7246e7a9fd015fb0b28b330a8d4142151a33f03e6a497754f4b1f6a8e" dependencies = [ "dissimilar", "glob", "serde", "serde_derive", "serde_json", "target-triple", "termcolor", "toml", ] [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "winapi-util" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" dependencies = [ "windows-sys", ] [[package]] name = "windows-link" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ "windows-link", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" [[package]] name = "windows_aarch64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_i686_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" [[package]] name = "windows_i686_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" [[package]] name = "windows_i686_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" [[package]] name = "windows_x86_64_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" [[package]] name = "windows_x86_64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" [[package]] name = "windows_x86_64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3edebf492c8125044983378ecb5766203ad3b4c2f7a922bd7dd207f6d443e95" inventory-0.3.21/Cargo.toml0000644000000033730000000000100111600ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.62" name = "inventory" version = "0.3.21" authors = ["David Tolnay "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Typed distributed plugin registration" documentation = "https://docs.rs/inventory" readme = "README.md" keywords = ["linkage"] categories = [ "development-tools::build-utils", "development-tools::procedural-macro-helpers", "no-std", "no-std::no-alloc", ] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/inventory" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = [ "--generate-link-to-definition", "--extern-html-root-url=core=https://doc.rust-lang.org", "--extern-html-root-url=alloc=https://doc.rust-lang.org", "--extern-html-root-url=std=https://doc.rust-lang.org", ] [lib] name = "inventory" path = "src/lib.rs" [[example]] name = "flags" path = "examples/flags.rs" [[test]] name = "compiletest" path = "tests/compiletest.rs" [[test]] name = "test" path = "tests/test.rs" [dev-dependencies.rustversion] version = "1.0" [dev-dependencies.trybuild] version = "1.0.89" features = ["diff"] [target.'cfg(target_family = "wasm")'.dependencies.rustversion] version = "1.0" inventory-0.3.21/Cargo.toml.orig000064400000000000000000000016501046102023000146350ustar 00000000000000[package] name = "inventory" version = "0.3.21" authors = ["David Tolnay "] categories = ["development-tools::build-utils", "development-tools::procedural-macro-helpers", "no-std", "no-std::no-alloc"] description = "Typed distributed plugin registration" documentation = "https://docs.rs/inventory" edition = "2021" keywords = ["linkage"] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/inventory" rust-version = "1.62" [target.'cfg(target_family = "wasm")'.dependencies] rustversion = "1.0" [dev-dependencies] rustversion = "1.0" trybuild = { version = "1.0.89", features = ["diff"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = [ "--generate-link-to-definition", "--extern-html-root-url=core=https://doc.rust-lang.org", "--extern-html-root-url=alloc=https://doc.rust-lang.org", "--extern-html-root-url=std=https://doc.rust-lang.org", ] inventory-0.3.21/LICENSE-APACHE000064400000000000000000000227731046102023000137030ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS inventory-0.3.21/LICENSE-MIT000064400000000000000000000017771046102023000134140ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. inventory-0.3.21/README.md000064400000000000000000000110001046102023000132130ustar 00000000000000## Typed distributed plugin registration [github](https://github.com/dtolnay/inventory) [crates.io](https://crates.io/crates/inventory) [docs.rs](https://docs.rs/inventory) [build status](https://github.com/dtolnay/inventory/actions?query=branch%3Amaster) This crate provides a way to set up a plugin registry into which plugins can be registered from any source file linked into your application. There does not need to be a central list of all the plugins. ```toml [dependencies] inventory = "0.3" ``` *Supports rustc 1.62+*
# Examples Suppose we are writing a command line flags library and want to allow any source file in the application to register command line flags that are relevant to it. This is the flag registration style used by [gflags] and is better suited for large scale development than maintaining a single central list of flags, as the central list would become an endless source of merge conflicts in an application developed simultaneously by thousands of developers. [gflags]: https://gflags.github.io/gflags/ ### Instantiating the plugin registry Let's use a `struct Flag` as the plugin type, which will contain the short name of the flag like `-v`, the full name like `--verbose`, and maybe other information like argument type and help text. We instantiate a plugin registry with an invocation of `inventory::collect!`. ```rust pub struct Flag { short: char, name: &'static str, /* ... */ } impl Flag { pub const fn new(short: char, name: &'static str) -> Self { Flag { short, name } } } inventory::collect!(Flag); ``` This `collect!` call must be in the same crate that defines the plugin type. This macro does not "run" anything so place it outside of any function body. ### Registering plugins Now any crate with access to the `Flag` type can register flags as a plugin. Plugins can be registered by the same crate that declares the plugin type, or by any downstream crate. ```rust inventory::submit! { Flag::new('v', "verbose") } ``` The `submit!` macro does not "run" anything so place it outside of any function body. In particular, note that all `submit!` invocations across all source files linked into your application all take effect simultaneously. A `submit!` invocation is not a statement that needs to be called from `main` in order to execute. ### Iterating over plugins The value `inventory::iter::` is an iterator with element type `&'static T` that iterates over all plugins registered of type `T`. ```rust for flag in inventory::iter:: { println!("-{}, --{}", flag.short, flag.name); } ``` There is no guarantee about the order that plugins of the same type are visited by the iterator. They may be visited in any order.
## How it works Inventory is built on runtime initialization functions similar to `__attribute__((constructor))` in C, and similar to the [`ctor`] crate. Each call to `inventory::submit!` produces a shim that evaluates the given expression and registers it into a registry of its corresponding type. This registration happens dynamically as part of life-before-main for statically linked elements. Elements brought in by a dynamically loaded library are registered at the time that dlopen occurs. [`ctor`]: https://github.com/mmastrac/rust-ctor Platform support includes Linux, macOS, iOS, FreeBSD, Android, Windows, WebAssembly, and a few others. Beyond this, other platforms will simply find that no plugins have been registered. For a different approach to plugin registration that *does not* involve life-before-main, see the [`linkme`] crate. [`linkme`]: https://github.com/dtolnay/linkme
#### License Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. inventory-0.3.21/examples/flags.rs000064400000000000000000000005561046102023000152320ustar 00000000000000struct Flag { short: char, name: &'static str, } impl Flag { const fn new(short: char, name: &'static str) -> Self { Flag { short, name } } } inventory::submit! { Flag::new('v', "verbose") } inventory::collect!(Flag); fn main() { for flag in inventory::iter:: { println!("-{}, --{}", flag.short, flag.name); } } inventory-0.3.21/src/lib.rs000064400000000000000000000426551046102023000136630ustar 00000000000000//! [![github]](https://github.com/dtolnay/inventory) [![crates-io]](https://crates.io/crates/inventory) [![docs-rs]](https://docs.rs/inventory) //! //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust //! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs //! //!
//! //! **Typed distributed plugin registration.** //! //! This crate provides a way to set up a plugin registry into which plugins //! can be registered from any source file linked into your application. There //! does not need to be a central list of all the plugins. //! //! # Examples //! //! Suppose we are writing a command line flags library and want to allow any //! source file in the application to register command line flags that are //! relevant to it. //! //! This is the flag registration style used by [gflags] and is better suited //! for large scale development than maintaining a single central list of flags, //! as the central list would become an endless source of merge conflicts in an //! application developed simultaneously by thousands of developers. //! //! [gflags]: https://gflags.github.io/gflags/ //! //! ## Instantiating the plugin registry //! //! Let's use a `struct Flag` as the plugin type, which will contain the short //! name of the flag like `-v`, the full name like `--verbose`, and maybe other //! information like argument type and help text. We instantiate a plugin //! registry with an invocation of `inventory::collect!`. //! //! ``` //! pub struct Flag { //! short: char, //! name: &'static str, //! /* ... */ //! } //! //! impl Flag { //! pub const fn new(short: char, name: &'static str) -> Self { //! Flag { short, name } //! } //! } //! //! inventory::collect!(Flag); //! ``` //! //! This `collect!` call must be in the same crate that defines the plugin type. //! This macro does not "run" anything so place it outside of any function body. //! //! ## Registering plugins //! //! Now any crate with access to the `Flag` type can register flags as a plugin. //! Plugins can be registered by the same crate that declares the plugin type, //! or by any downstream crate. //! //! ``` //! # struct Flag; //! # //! # impl Flag { //! # const fn new(short: char, name: &'static str) -> Self { //! # Flag //! # } //! # } //! # //! # inventory::collect!(Flag); //! # //! inventory::submit! { //! Flag::new('v', "verbose") //! } //! # //! # fn main() {} //! ``` //! //! The `submit!` macro does not "run" anything so place it outside of any //! function body. In particular, note that all `submit!` invocations across all //! source files linked into your application all take effect simultaneously. A //! `submit!` invocation is not a statement that needs to be called from `main` //! in order to execute. //! //! ## Iterating over plugins //! //! The value `inventory::iter::` is an iterator with element type `&'static //! T` that iterates over all plugins registered of type `T`. //! //! ``` //! # struct Flag { //! # short: char, //! # name: &'static str, //! # } //! # //! # inventory::collect!(Flag); //! # //! for flag in inventory::iter:: { //! println!("-{}, --{}", flag.short, flag.name); //! } //! ``` //! //! There is no guarantee about the order that plugins of the same type are //! visited by the iterator. They may be visited in any order. //! //! ## WebAssembly and constructors //! //! `inventory` supports all WebAssembly targets, including //! `wasm*-unknown-unknown`. However, in unusual circumstances, ensuring that //! constructors run may require some extra effort. The Wasm linker will //! synthesize a function `extern "C" unsafe fn __wasm_call_ctors()` which calls //! all constructors when invoked; this function will *not* be exported from the //! module unless you do so explicitly. Depending on the result of a heuristic, //! the linker may or may not insert a call to this function from the beginning //! of every function that your module exports. Specifically, it regards a //! module as having "command-style linkage" if: //! //! * it is not relocatable; //! * it is not a position-independent executable; //! * and it does not call `__wasm_call_ctors`, directly or indirectly, from any //! exported function. //! //! The linker expects that the embedder will call into a command-style module //! only once per instantiation. Violation of this expectation can result in //! `__wasm_call_ctors` being called multiple times. This is dangerous in //! general, but safe and mostly harmless in the case of constructors generated //! by `inventory`, which are idempotent. //! //! If you are building a module which relies on constructors and may be called //! into multiple times per instance, you should export `__wasm_call_ctors` (or //! a wrapper around it) and ensure that the embedder calls it immediately after //! instantiation. Even though `inventory` may work fine without this, it is //! still good practice, because it avoids unnecessary overhead from repeated //! constructor invocation. It also can prevent unsoundness if some of your //! constructors are generated by other crates or other programming languages. //! //! ``` //! #[cfg(target_family = "wasm")] //! unsafe extern "C" { //! fn __wasm_call_ctors(); //! } //! //! fn main() { //! #[cfg(target_family = "wasm")] //! unsafe { //! __wasm_call_ctors(); //! } //! } //! ``` #![doc(html_root_url = "https://docs.rs/inventory/0.3.21")] #![no_std] #![deny(unsafe_op_in_unsafe_fn)] #![allow( clippy::doc_markdown, clippy::empty_enum, clippy::expl_impl_clone_on_copy, clippy::let_underscore_untyped, clippy::let_unit_value, clippy::must_use_candidate, clippy::new_without_default, clippy::semicolon_if_nothing_returned, // https://github.com/rust-lang/rust-clippy/issues/7324 )] // Not public API. #[doc(hidden)] pub extern crate core; use core::cell::UnsafeCell; use core::marker::PhantomData; use core::ops::Deref; use core::ptr; #[cfg(target_family = "wasm")] use core::sync::atomic::AtomicBool; use core::sync::atomic::{AtomicPtr, Ordering}; // Not public API. Used by generated code. #[doc(hidden)] pub struct Registry { head: AtomicPtr, } // Not public API. Used by generated code. #[doc(hidden)] pub struct Node { pub value: &'static dyn ErasedNode, pub next: UnsafeCell>, #[cfg(target_family = "wasm")] pub initialized: AtomicBool, } // The `value` is Sync, and `next` is only mutated during submit, which is prior // to any reads. unsafe impl Sync for Node {} // Not public API. Used by generated code. #[doc(hidden)] pub trait ErasedNode: Sync { // SAFETY: requires *node.value is of type Self. unsafe fn submit(&self, node: &'static Node); } impl ErasedNode for T { unsafe fn submit(&self, node: &'static Node) { unsafe { T::registry().submit(node); } } } /// Trait bound corresponding to types that can be iterated by inventory::iter. /// /// This trait cannot be implemented manually. Instead use the [`collect`] macro /// which expands to an implementation of this trait for the given type. /// /// # Examples /// /// ``` /// use inventory::Collect; /// /// fn count_plugins() -> usize { /// inventory::iter::.into_iter().count() /// } /// ``` pub trait Collect: Sync + Sized + 'static { #[doc(hidden)] fn registry() -> &'static Registry; } impl Registry { // Not public API. Used by generated code. pub const fn new() -> Self { Registry { head: AtomicPtr::new(ptr::null_mut()), } } // SAFETY: requires type of *new.value matches the $ty surrounding the // declaration of this registry in inventory::collect macro. unsafe fn submit(&'static self, new: &'static Node) { // The WebAssembly linker uses an unreliable heuristic to determine // whether a module is a "command-style" linkage, for which it will // insert a call to `__wasm_call_ctors` at the top of every exported // function. It expects that the embedder will call into such modules // only once per instantiation. If this heuristic goes wrong, we can end // up having our constructors invoked multiple times, which without this // safeguard would lead to our registry's linked list becoming circular. // On non-Wasm platforms, this check is unnecessary, so we skip it. #[cfg(target_family = "wasm")] if new.initialized.swap(true, Ordering::Relaxed) { return; } let mut head = self.head.load(Ordering::Relaxed); loop { unsafe { *new.next.get() = head.as_ref(); } let new_ptr = new as *const Node as *mut Node; match self .head .compare_exchange(head, new_ptr, Ordering::Release, Ordering::Relaxed) { Ok(_) => return, Err(prev) => head = prev, } } } } /// An iterator over plugins registered of a given type. /// /// The value `inventory::iter::` is an iterator with element type `&'static /// T`. /// /// There is no guarantee about the order that plugins of the same type are /// visited by the iterator. They may be visited in any order. /// /// # Examples /// /// ``` /// # struct Flag { /// # short: char, /// # name: &'static str, /// # } /// # /// # inventory::collect!(Flag); /// # /// # const IGNORE: &str = stringify! { /// use my_flags::Flag; /// # }; /// /// fn main() { /// for flag in inventory::iter:: { /// println!("-{}, --{}", flag.short, flag.name); /// } /// } /// ``` /// /// Refer to the [crate level documentation](index.html) for a complete example /// of instantiating a plugin registry and submitting plugins. #[allow(non_camel_case_types)] pub type iter = private::iter; mod void_iter { enum Void {} #[repr(C, packed)] pub struct Iter([*const T; 0], Void); unsafe impl Send for Iter {} unsafe impl Sync for Iter {} } mod value_iter { #[doc(hidden)] pub use crate::private::iter::iter; } mod private { // Based on https://github.com/dtolnay/ghost #[allow(non_camel_case_types)] pub enum iter { __Phantom(crate::void_iter::Iter), iter, } #[doc(hidden)] pub use crate::value_iter::*; } #[doc(hidden)] pub use crate::private::*; const _: () = { fn into_iter() -> Iter { let head = T::registry().head.load(Ordering::Acquire); Iter { // Head pointer is always null or valid &'static Node. node: unsafe { head.as_ref() }, marker: PhantomData, } } impl IntoIterator for iter { type Item = &'static T; type IntoIter = Iter; fn into_iter(self) -> Self::IntoIter { into_iter() } } #[doc(hidden)] impl Deref for iter { type Target = fn() -> Iter; fn deref(&self) -> &Self::Target { &(into_iter as fn() -> Iter) } } pub struct Iter { node: Option<&'static Node>, marker: PhantomData, } impl Iterator for Iter { type Item = &'static T; fn next(&mut self) -> Option { let node = self.node?; unsafe { let value_ptr = (node.value as *const dyn ErasedNode).cast::(); self.node = *node.next.get(); Some(&*value_ptr) } } } impl Clone for Iter { fn clone(&self) -> Self { Self { node: self.node, marker: PhantomData, } } } }; /// Associate a plugin registry with the specified type. /// /// This call must be in the same crate that defines the plugin type. This macro /// does not "run" anything so place it outside of any function body. /// /// # Examples /// /// Suppose we are writing a command line flags library and want to allow any /// source file in the application to register command line flags that are /// relevant to it. /// /// This is the flag registration style used by [gflags] and is better suited /// for large scale development than maintaining a single central list of flags, /// as the central list would become an endless source of merge conflicts. /// /// [gflags]: https://gflags.github.io/gflags/ /// /// ``` /// pub struct Flag { /// short: char, /// name: &'static str, /// /* ... */ /// } /// /// inventory::collect!(Flag); /// ``` /// /// Refer to the [crate level documentation](index.html) for a complete example /// of submitting plugins and iterating a plugin registry. #[macro_export] macro_rules! collect { ($ty:ty) => { impl $crate::Collect for $ty { #[inline] fn registry() -> &'static $crate::Registry { static REGISTRY: $crate::Registry = $crate::Registry::new(); ®ISTRY } } }; } /// Enter an element into the plugin registry corresponding to its type. /// /// This call may be in the same crate that defines the type, or downstream in /// any crate that depends on that crate. /// /// This macro does not "run" anything so place it outside of any function body. /// In particular, note that all `submit!` invocations across all source files /// linked into your application all take effect simultaneously. A `submit!` /// invocation is not a statement that needs to be called from `main` in order /// to execute. /// /// # Examples /// /// Put `submit!` invocations outside of any function body. /// /// ``` /// # struct Flag; /// # /// # impl Flag { /// # const fn new(short: char, name: &'static str) -> Self { /// # Flag /// # } /// # } /// # /// # inventory::collect!(Flag); /// # /// inventory::submit! { /// Flag::new('v', "verbose") /// } /// # /// # fn main() {} /// ``` /// /// Do not try to invoke `submit!` from inside of a function body as it does not /// do what you want. /// /// ```compile_fail /// // Do not do this. /// fn submit_flags(has_verbose_flag: bool) { /// if has_verbose_flag { /// inventory::submit! { /// Flag::new('v', "verbose") /// } /// } /// } /// ``` /// /// Refer to the [crate level documentation](index.html) for a complete example /// of instantiating and iterating a plugin registry. #[macro_export] macro_rules! submit { ($($value:tt)*) => { $crate::__do_submit! { { $($value)* } { $($value)* } } }; } // Not public API. #[cfg(target_family = "wasm")] #[doc(hidden)] pub mod __private { #[doc(hidden)] pub use rustversion::attr; } // Not public API. #[doc(hidden)] #[macro_export] macro_rules! __do_submit { (used={ $($used:tt)+ } $($value:tt)*) => { #[allow(non_upper_case_globals)] const _: () = { static __INVENTORY: $crate::Node = $crate::Node { value: &{ $($value)* }, next: $crate::core::cell::UnsafeCell::new($crate::core::option::Option::None), #[cfg(target_family = "wasm")] initialized: $crate::core::sync::atomic::AtomicBool::new(false), }; #[cfg_attr(any(target_os = "linux", target_os = "android"), link_section = ".text.startup")] unsafe extern "C" fn __ctor() { unsafe { $crate::ErasedNode::submit(__INVENTORY.value, &__INVENTORY) } } // Linux/ELF: https://www.exploit-db.com/papers/13234 // // macOS: https://blog.timac.org/2016/0716-constructor-and-destructor-attributes/ // // Why .CRT$XCU on Windows? https://www.cnblogs.com/sunkang/archive/2011/05/24/2055635.html // 'I'=C init, 'C'=C++ init, 'P'=Pre-terminators and 'T'=Terminators $($used)+ #[cfg_attr( all( not(target_family = "wasm"), any( target_os = "linux", target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "haiku", target_os = "illumos", target_os = "netbsd", target_os = "openbsd", target_os = "none", ) ), link_section = ".init_array", )] #[cfg_attr( target_family = "wasm", $crate::__private::attr( any(all(stable, since(1.85)), since(2024-12-18)), link_section = ".init_array", ), )] #[cfg_attr( any(target_os = "macos", target_os = "ios"), link_section = "__DATA,__mod_init_func,mod_init_funcs", )] #[cfg_attr(windows, link_section = ".CRT$XCU")] static __CTOR: unsafe extern "C" fn() = __ctor; }; }; ({ #![used($($used:tt)+)] $($value:tt)* } { $pound:tt $bang:tt $brackets:tt $($dup:tt)* }) => { $crate::__do_submit! { used={ $pound $brackets } $($value)* } }; ({ $($value:tt)* } { $($dup:tt)* }) => { $crate::__do_submit! { used={ #[used] } $($value)* } }; } inventory-0.3.21/tests/compiletest.rs000064400000000000000000000003261046102023000160050ustar 00000000000000#[rustversion::attr(not(nightly), ignore = "requires nightly")] #[cfg_attr(miri, ignore = "incompatible with miri")] #[test] fn ui() { let t = trybuild::TestCases::new(); t.compile_fail("tests/ui/*.rs"); } inventory-0.3.21/tests/test.rs000064400000000000000000000003031046102023000144270ustar 00000000000000use std::mem; pub struct Thing(pub usize); #[test] fn test_iter() { assert_eq!(0, mem::size_of::>()); assert_eq!(1, mem::align_of::>()); } inventory-0.3.21/tests/ui/collect-unsized.rs000064400000000000000000000001061046102023000171720ustar 00000000000000pub struct Unsized(str); inventory::collect!(Unsized); fn main() {} inventory-0.3.21/tests/ui/collect-unsized.stderr000064400000000000000000000012061046102023000200530ustar 00000000000000error[E0277]: the size for values of type `str` cannot be known at compilation time --> tests/ui/collect-unsized.rs:3:21 | 3 | inventory::collect!(Unsized); | ^^^^^^^ doesn't have a size known at compile-time | = help: within `Unsized`, the trait `Sized` is not implemented for `str` note: required because it appears within the type `Unsized` --> tests/ui/collect-unsized.rs:1:12 | 1 | pub struct Unsized(str); | ^^^^^^^ note: required by a bound in `Collect` --> src/lib.rs | | pub trait Collect: Sync + Sized + 'static { | ^^^^^ required by this bound in `Collect` inventory-0.3.21/tests/ui/non-sync.rs000064400000000000000000000007231046102023000156370ustar 00000000000000use std::rc::Rc; use std::thread; struct Thing(Rc); inventory::collect!(Thing); fn clone_all() { for thing in inventory::iter:: { let _ = Rc::clone(&thing.0); } } fn main() { // It would be bad if this were allowed. These threads would race on the // nonatomic reference counts. let thread1 = thread::spawn(clone_all); let thread2 = thread::spawn(clone_all); thread1.join().unwrap(); thread2.join().unwrap(); } inventory-0.3.21/tests/ui/non-sync.stderr000064400000000000000000000011261046102023000165140ustar 00000000000000error[E0277]: `Rc` cannot be shared between threads safely --> tests/ui/non-sync.rs:6:21 | 6 | inventory::collect!(Thing); | ^^^^^ `Rc` cannot be shared between threads safely | = help: within `Thing`, the trait `Sync` is not implemented for `Rc` note: required because it appears within the type `Thing` --> tests/ui/non-sync.rs:4:8 | 4 | struct Thing(Rc); | ^^^^^ note: required by a bound in `Collect` --> src/lib.rs | | pub trait Collect: Sync + Sized + 'static { | ^^^^ required by this bound in `Collect` inventory-0.3.21/tests/ui/outer-attr.rs000064400000000000000000000002131046102023000161730ustar 00000000000000#![feature(used_with_arg)] struct Thing; inventory::collect!(Thing); inventory::submit! { #[used(linker)] Thing } fn main() {} inventory-0.3.21/tests/ui/outer-attr.stderr000064400000000000000000000003041046102023000170530ustar 00000000000000error: `#[used]` attribute cannot be used on expressions --> tests/ui/outer-attr.rs:8:5 | 8 | #[used(linker)] | ^^^^^^^^^^^^^^^ | = help: `#[used]` can only be applied to statics inventory-0.3.21/tests/ui/submit-nonconst.rs000064400000000000000000000002271046102023000172340ustar 00000000000000struct Thing; impl Thing { fn new() -> Self { Thing } } inventory::collect!(Thing); inventory::submit!(Thing::new()); fn main() {} inventory-0.3.21/tests/ui/submit-nonconst.stderr000064400000000000000000000006011046102023000201070ustar 00000000000000error[E0015]: cannot call non-const associated function `Thing::new` in statics --> tests/ui/submit-nonconst.rs:11:20 | 11 | inventory::submit!(Thing::new()); | ^^^^^^^^^^^^ | = note: calls in statics are limited to constant functions, tuple structs and tuple variants = note: consider wrapping this expression in `std::sync::LazyLock::new(|| ...)` inventory-0.3.21/tests/ui/submit-unrecognized.rs000064400000000000000000000000741046102023000200670ustar 00000000000000pub struct Thing; inventory::submit!(Thing); fn main() {} inventory-0.3.21/tests/ui/submit-unrecognized.stderr000064400000000000000000000010661046102023000207500ustar 00000000000000error[E0277]: the trait bound `Thing: ErasedNode` is not satisfied --> tests/ui/submit-unrecognized.rs:3:1 | 3 | inventory::submit!(Thing); | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Collect` is not implemented for `Thing` | = note: required for `Thing` to implement `ErasedNode` = note: required for the cast from `&Thing` to `&'static (dyn ErasedNode + 'static)` = note: this error originates in the macro `$crate::__do_submit` which comes from the expansion of the macro `inventory::submit` (in Nightly builds, run with -Z macro-backtrace for more info) inventory-0.3.21/tests/ui/used-linker.rs000064400000000000000000000001601046102023000163100ustar 00000000000000struct Thing; inventory::collect!(Thing); inventory::submit! { #![used(linker)] Thing } fn main() {} inventory-0.3.21/tests/ui/used-linker.stderr000064400000000000000000000004771046102023000172020ustar 00000000000000error[E0658]: `#[used(linker)]` is currently unstable --> tests/ui/used-linker.rs:6:5 | 6 | #![used(linker)] | ^^^^^^^^^^^^^^^^ | = note: see issue #93798 for more information = help: add `#![feature(used_with_arg)]` to the crate attributes to enable