This crate provides the SingletonSet data structure, which makes it easy to
store a single instance each of various types within a single set.
This data structure can be used to create a locally-scoped Singleton out of any data types within it. It ensures there is only one instance of any type, similar to a Singleton, without polluting the global scope.
Features
- Type Safety: Ensures that only one value per type is present in the
set, using Rust's type system and
std::any::TypeId. - Flexible Initialization: Types that implement
Defaultcan be automatically initialized, or any type can be initialized from a value or closure for fully customizable initialization.
Example Usage
use SingletonSet;
Installation
Use cargo add singletonset or add the following dependency to your
Cargo.toml file:
[]
= "0.1"
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions, bug reports, or feature requests.
License
Licensed under either of the Apache License, Version 2.0 or the MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.