Crate uncased

source ·
Expand description

Case-preserving, ASCII case-insensitive no_std string types.

An uncased string is case-preserving. That is, the string itself contains cased characters, but comparison (including ordering, equality, and hashing) is ASCII case-insensitive.

use uncased::UncasedStr;

let x: &UncasedStr = "hello!".into();
let y: &UncasedStr = "HelLo!".into();

assert_eq!(x, y);
assert_eq!(x.as_str(), "hello!");
assert_eq!(y.as_str(), "HelLo!");

let x_sub = &x[..4];
let y_sub = &y[..4];
assert_eq!(x_sub, y_sub);
assert_eq!(x_sub.as_str(), "hell");
assert_eq!(y_sub.as_str(), "HelL");

§Unicode

This crate does not perform Unicode case-folding. For Unicode case-folding, see unicase.

§Features and no_std

Crate features:

  • alloc (default) - enables the Uncased type
  • with-serde - enables (de)serializing of UncasedStr via serde
  • with-serde-alloc - enables alloc, (de)serializing of UncasedStr and Uncased via serde

This crate is #![no_std] compatible. By default, the alloc feature is enabled, which enables the Uncased type but requires alloc support. To disable the feature, disable this crate’s default features:

[dependencies]
uncased = { version = "0.9", default-features = false }

In addition to the alloc feature, support for (de)serializing UncasedStr with serde can be enabled via the with-serde feature. Support for (de)serserializing both UncasedStr and Uncased can be enabled via the with-serde-alloc feature, which implicitly enables the alloc feature.

Structs§

  • An uncased (case-insensitive, case-preserving), owned or borrowed ASCII string.
  • A cost-free reference to an uncased (case-insensitive, case-preserving) ASCII string.

Traits§

  • Helper trait to convert string-like references to &UncasedStr.

Functions§

  • Returns true if s1 and s2 are equal without considering case.