TypeID Prefix
A Rust library that implements a type-safe version of the TypePrefix section of the TypeID Specification.
Features
- Type-safe: Ensures that TypeID prefixes conform to the specification.
- Validation: Provides robust validation for TypeID prefixes.
- Sanitization: Offers methods to clean and sanitize input strings into valid TypeID prefixes.
- Zero-cost abstractions: Designed to have minimal runtime overhead.
- Optional tracing: Integrates with the
tracingcrate for logging (optional feature).
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
To enable tracing support, add:
[]
= { = "1.0.0", = ["instrument"] }
Usage
Basic Usage
use ;
use TryFrom;
Validation
The TypeIdPrefix type ensures that all instances conform to the TypeID specification:
- Maximum length of 63 characters
- Contains only lowercase ASCII letters and underscores
- Does not start or end with an underscore
- Starts and ends with a lowercase letter
use TypeIdPrefix;
use TryFrom;
Sanitization
The Sanitize trait provides a method to clean and create a valid TypeIdPrefix from any string:
use Sanitize;
Optional Tracing
When the instrument feature is enabled, the crate will log validation errors using the tracing crate:
[]
= { = "1.0.0", = ["instrument"] }
use Sanitize;
Use Cases
- Database Systems: Use
TypeIdPrefixto ensure consistent and valid type prefixes for database schemas or ORM mappings. - API Development: Validate and sanitize user input for API endpoints that require type prefixes.
- Code Generation: Generate valid type prefixes for code generation tools or macros.
- Configuration Management: Ensure configuration keys or identifiers conform to a consistent format.
Safety and Correctness
This crate has been thoroughly tested and verified:
- Comprehensive unit tests
- Property-based testing with
proptest - Fuzz testing
- Formal verification with Kani
These measures ensure that the crate behaves correctly and never panics under normal usage.
Minimum Supported Rust Version (MSRV)
This crate is guaranteed to compile on Rust 1.60.0 and later.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Credits
This crate implements a portion of the TypeID Specification created by Jetpack.io.