const-str 0.2.1

compile-time string operations
Documentation

Compile-time string operations

MSRV: Rust 1.52.0

Examples

assert_eq!(const_str::to_lowercase!("HELLO"), "hello");

assert_eq!(const_str::to_uppercase!("hello"), "HELLO");

assert_eq!(const_str::replace!("this is old", "old", "new"), "this is new");

assert_eq!(const_str::to_str!(1_u8 + 1_u8), "2");

const PROMPT: &str = "The answer is";
const ANSWER: usize = 42;
const MESSAGE: &str = const_str::concat!(PROMPT, " ", ANSWER);

assert_eq!(MESSAGE, "The answer is 42");

feature verify-regex

use regex::Regex;
let re = const_str::verified_regex!(r"^\d{4}-\d{2}-\d{2}$");
assert!(Regex::new(re).is_ok());

const_str::regex_assert_match!(r"^\d{4}-\d{2}-\d{2}$", "2014-01-01");

feature verify-http

use http::header::HeaderName;
let name = const_str::verified_header_name!("content-md5");
assert_eq!(HeaderName::from_static(name).as_str(), "content-md5");