Qubit Case
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 one core
CaseStyleenum, five convenience constants, and focused parsing and validation errors. - 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-hyphenLOWER_UNDERSCORE:lower_underscoreLOWER_CAMEL:lowerCamelUPPER_CAMEL:UpperCamelUPPER_UNDERSCORE:UPPER_UNDERSCORE
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
let value = LOWER_HYPHEN.to;
assert_eq!;
LOWER_CAMEL
.validate
.expect;
let constant = LOWER_CAMEL
.checked_to
.expect;
assert_eq!;
assert!;
assert_eq!;
API Reference
Types
CaseStyle- supported case styles and conversion methods.CaseStyleError- error returned when parsing an unknown style name.CaseStyleValidationError- error returned when a value does not match the expected style.
Constants
LOWER_HYPHENLOWER_UNDERSCORELOWER_CAMELUPPER_CAMELUPPER_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)performs permissive best-effort conversion without validating the source or guaranteeing that invalid input matches the target style.CaseStyle::validate(value)validates an identifier and reports a mismatch.CaseStyle::checked_to(target, value)validates the source before converting it.CaseStyle::matches(value)checks whether an identifier strictly follows a style.
Trait Implementations
Displayformats a style using its canonical lower-hyphen name.FromStrparses the names accepted byCaseStyle::of.
Testing & Code Coverage
This project tests successful and checked conversions, validation errors, style parsing and display, style matching, CamelCase acronym boundaries, digit boundaries, empty input, Unicode safety, and best-effort conversion behavior.
Running Tests
# Run all tests
# Run with coverage report
# Generate text format report
# Run CI checks (format, clippy, test, coverage, audit)
Coverage Metrics
See 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 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.shbefore submitting PRs.
Author
Haixing Hu
Related Projects
More Rust libraries from Qubit are published under the qubit-ltd organization on GitHub.
Repository: https://github.com/qubit-ltd/rs-case