Brief
A basic Atom (string) registry for use with ID strings.
For when an application contains and passes around many constant strings (mainly de/serialized strings), this should reduce the overall memory footprint and slightly increase cache usage
Warning: The performance implications of this crate should be tested to ensure it's a good fit for your use-case. There are many sitatuations where such a caching mechanism is simply unnecessary and this crate may easily harm performance due to the memory allocation required to register an atom, as well as the hash-lookup.
Inspiration for this project:
- Use Arc instead of Vec - Logan Smith (YouTube/@_noisecode)
- Atom Tables - Microsoft Windows
Usage
Atoms can be created directly and either passed by ref into functions, or cloned to avoid Rust's ownership semantics.
use Atom;
Ideally atoms should be registered into a global table. This will provide lookups to return an existing atom if present, or create one if not. Atoms on there own may reduce the overall memory footprint, but with a registry the same string will always yield the same atom.
use *;
Registries are indirect, support Send
/Sync
and can be cheaply cloned.
Cloned registries point to the same atom table and updates in one will be reflected in both.
Changelog
Version | Changes |
---|---|
0.1.0 | Initial-release |
0.1.1 | Fixed potential hash-collision bug |
0.1.2 | Updated readme usage. Improved construct semantics |
0.1.3 | Added Display trait to Atom |
0.1.4 | Added PartialEq and Eq traits to Atom |
0.1.5 | Added feature "serde" to implement Deserialize /Serialize |
0.1.6 | Added Default trait to Atom and AtomRegistry |
0.1.7 | Added infallible FromStr trait to Atom (I need this for use in higher projects, so it's via feature "from_str"). Added Hash trait to Atom |
Contributing
Got some idea, feedback, question or found a bug? Feel free to open an issue at any time!
License
TOMT_Atom is dual-licensed under either:
- MIT License (in repository or from [source][licence-MIT-remote])
- Apache License, Version 2.0 (in repository or from source)
This means you can select the license you prefer! This dual-licensing approach is the de-facto standard in the Rust ecosystem and there are good reasons to include both.