stringz

Crates.iostringz
lib.rsstringz
version0.4.1
sourcesrc
created_at2024-04-22 07:16:23.226243
updated_at2024-05-27 07:23:12.438831
descriptionA way to use strings in generic paramters
homepage
repositoryhttps://github.com/NichtsHsu/structz
max_upload_size
id1216020
size6,450
Nihil (NichtsHsu)

documentation

https://docs.rs/stringz

README

stringz

Convert strings to types to make it available as generic parameters.

Install

cargo add stringz

For no_std users:

cargo add stringz --no-default-features 

Example

use stringz::{TypedString, string};

fn test_hello<T: TypedString>() {
    assert_eq!(T::value(), "hello");
}

test_hello::<string!("hello")>();

Explanation

The string macro converts "hello" to the following tuple type:

(Character<'h'>, Character<'e'>, Character<'l'>, Character<'l'>, Character<'o'>)

Note: The above form is only for ease of understanding, the actual Tuple type of tuplez is used.

All generated types are zero-sized types:

use stringz::string;
assert_eq!(std::mem::size_of::<string!("no matter how long it is")>(), 0);
Commit count: 55

cargo fmt