4 releases (2 breaking)

new 0.3.0 May 3, 2024
0.2.0 Apr 26, 2024
0.1.2 Apr 24, 2024
0.1.1 Apr 23, 2024
0.1.0 Apr 22, 2024

#1830 in Data structures

Download history 436/week @ 2024-04-21 146/week @ 2024-04-28

582 downloads per month
Used in structz

MIT/Apache

5KB

stringz

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

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);

lib.rs:

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

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);

Dependencies

~0.5–1MB
~21K SLoC