This crate provides an encoding of type-level strings as types.
Examples
Indexing
This example demonstrates how you can use type-level strings,
and the Index
trait, to access fields of generic types by name.
use Index;
use ;
use Person;
use OtherPerson;
Macro expansion
This library reserves the right to change how it represent type-level strings internally in every single release, and cargo feature combination.
This only affects you if you expand the code generated by macros from this crate, and then use that expanded code instead of going through the macros.
Cargo features
-
"rust_1_46"
: Enables const functions intstr::utils
for comparing&str
and&[u8]
. -
"cmp_traits"
: Enables the traits for comparing type-level strings. -
"use_syn"
: Changes how literals passed to the macros of this crate are parsed to use thesyn
crate. Use this if there is some literal that could not be parsed but is a valid str/integer literal. -
"min_const_generics"
: changes the representation of type-level strings to use manychar
const parameter, making for better compiler errors for non-alphanumeric-ascii strings. Requires Rust 1.51.0. -
"const_generics"
: Changes the representation of type-level strings to use a&'static str
const parameter, making for better compiler errors, and a few more features. As of 2023-03-17, this feature can't be enabled, because it requires&'static str
to be stably usable as const parameters. Consider using"nightly_const_generics"
if this feature can't be used. -
"nightly_const_generics"
: Equivalent to the"const_generics"
feature, and enables the nightly compiler features to use&'static str
const parameters. -
"for_examples"
: Enables thefor_examples
module, with a few types used in documentation examples.
No-std support
This crate is unconditionally #![no_std]
, and can be used anywhere that Rust can be.
Minimum Supported Rust Version
This crate supports Rust versions back to Rust 1.40.0.