6 releases
Uses new Rust 2024
| 0.2.4 | Jul 27, 2026 |
|---|---|
| 0.2.3 | Jul 22, 2026 |
| 0.1.0 | Jun 29, 2026 |
#649 in Text processing
38KB
523 lines
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:
[dependencies]
qubit-case = "0.2"
Quick Start
use qubit_case::{
LOWER_CAMEL,
LOWER_HYPHEN,
UPPER_UNDERSCORE,
};
let value = LOWER_HYPHEN.to(LOWER_CAMEL, "hello-world");
assert_eq!(value, "helloWorld");
LOWER_CAMEL
.validate("http2Client")
.expect("the value should be lower camel case");
let constant = LOWER_CAMEL
.checked_to(UPPER_UNDERSCORE, "http2Client")
.expect("the source value should be valid");
assert_eq!(constant, "HTTP_2_CLIENT");
assert!(UPPER_UNDERSCORE.matches("HTTP_2_CLIENT"));
assert_eq!(LOWER_CAMEL.to_string(), "lower-camel");
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
# Run tests with the default feature set
cargo test
# Run tests with all declared features
cargo test --all-features
# Project CI checks
./ci-check.sh
# Check code coverage
./coverage.sh
License
Copyright (c) 2025 - 2026. Haixing Hu. All rights reserved.
Licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
Contributing
Contributions are welcome. Please follow the Rust API guidelines, keep public
API documentation and tests current, and run ./align-ci.sh to format code and
./ci-check.sh to satisfy CI requirements before submitting a pull request.
Author
Haixing Hu - Qubit Co. Ltd.
Repository: https://github.com/qubit-ltd/rs-case