# Qubit Case
[](https://github.com/qubit-ltd/rs-case/actions/workflows/ci.yml)
[](https://qubit-ltd.github.io/rs-case/coverage/)
[](https://crates.io/crates/qubit-case)
[](https://www.rust-lang.org)
[](LICENSE)
[](README.zh_CN.md)
Naming style detection and conversion helpers for Rust.
## Overview
Qubit Case converts ASCII identifiers between common naming styles used
by Java, C++, Python, XML, JSON, and Rust tooling through a compact Rust enum
API.
## Design Goals
- **Small API surface**: expose a single `CaseStyle` enum and five constants.
- **Consistent behavior**: provide stable conversion results for supported ASCII
identifier formats.
- **Strict matching**: validate whether a string conforms to a style.
- **Best-effort conversion**: convert inputs even when they are not strictly
valid for the source style.
- **No runtime dependencies**: keep the library lightweight.
## Supported Styles
- `LOWER_HYPHEN`: `lower-hyphen`
- `LOWER_UNDERSCORE`: `lower_underscore`
- `LOWER_CAMEL`: `lowerCamel`
- `UPPER_CAMEL`: `UpperCamel`
- `UPPER_UNDERSCORE`: `UPPER_UNDERSCORE`
## Installation
Add this to your `Cargo.toml`:
```toml
[dependencies]
qubit-case = "0.1"
```
## Quick Start
```rust
use qubit_case::{
LOWER_CAMEL,
LOWER_HYPHEN,
UPPER_UNDERSCORE,
};
let value = LOWER_HYPHEN.to(LOWER_CAMEL, "hello-world");
assert_eq!(value, "helloWorld");
let constant = LOWER_CAMEL.to(UPPER_UNDERSCORE, "http2Client");
assert_eq!(constant, "HTTP_2_CLIENT");
assert!(UPPER_UNDERSCORE.matches("HTTP_2_CLIENT"));
```
## API Reference
### Types
- [`CaseStyle`](https://docs.rs/qubit-case/latest/qubit_case/enum.CaseStyle.html) -
supported case styles and conversion methods.
- [`CaseStyleError`](https://docs.rs/qubit-case/latest/qubit_case/struct.CaseStyleError.html) -
error returned when parsing an unknown style name.
### Constants
- `LOWER_HYPHEN`
- `LOWER_UNDERSCORE`
- `LOWER_CAMEL`
- `UPPER_CAMEL`
- `UPPER_UNDERSCORE`
### Methods
- `CaseStyle::values()` returns all styles in reference order.
- `CaseStyle::of(name)` parses a style name case-insensitively, treating
hyphen and underscore as equivalent.
- `CaseStyle::name()` returns the canonical lower-hyphen style name.
- `CaseStyle::word_separator()` returns the style separator.
- `CaseStyle::to(target, value)` converts an identifier to another style.
- `CaseStyle::matches(value)` checks whether an identifier strictly follows a
style.
## Testing & Code Coverage
This project tests successful conversions, style parsing, style matching,
CamelCase acronym boundaries, digit boundaries, empty input, and best-effort
conversion behavior.
### Running Tests
```bash
# Run all tests
cargo test
# Run with coverage report
./coverage.sh
# Generate text format report
./coverage.sh text
# Run CI checks (format, clippy, test, coverage, audit)
./ci-check.sh
```
### Coverage Metrics
See [COVERAGE.md](COVERAGE.md) for detailed coverage statistics.
## Dependencies
This crate has no runtime dependencies.
## License
Copyright (c) 2025 - 2026. Haixing Hu.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
See [LICENSE](LICENSE) for the full license text.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
### Development Guidelines
- Follow the Rust API guidelines.
- Maintain comprehensive test coverage.
- Document all public APIs with examples when they clarify usage.
- Run `./ci-check.sh` before submitting PRs.
## Author
**Haixing Hu**
## Related Projects
More Rust libraries from Qubit are published under the
[qubit-ltd](https://github.com/qubit-ltd) organization on GitHub.
---
Repository: [https://github.com/qubit-ltd/rs-case](https://github.com/qubit-ltd/rs-case)