5 releases (2 stable)

1.0.1 Sep 13, 2020
1.0.0 Jul 16, 2020
0.0.3 Mar 6, 2020
0.0.2 Mar 6, 2020
0.0.1 Mar 6, 2020
Download history 6/week @ 2020-06-04 6/week @ 2020-07-02 3/week @ 2020-07-09 234/week @ 2020-07-16 95/week @ 2020-07-23 391/week @ 2020-07-30 239/week @ 2020-08-06 259/week @ 2020-08-13 532/week @ 2020-08-20 507/week @ 2020-08-27 898/week @ 2020-09-03 1004/week @ 2020-09-10 294/week @ 2020-09-17

1,502 downloads per month

Zlib OR Apache-2.0 OR MIT

9KB
174 lines

License:Zlib min-rust crates.io docs.rs

utf16_lit

Lets you change a standard Rust string literal (utf8) into a utf16 value at compile time.

This crate does not use syn or quote, so it actually builds fast.


lib.rs:

Provides a proc-macro for making utf-16 literals.

use utf16_lit::{utf16, utf16_null};

const EXAMPLE: &[u16] = utf16!("example");

const EXAMPLE_NULL: &[u16] = utf16_null!("example");

fn main() {
  let v: Vec<u16> = "example".encode_utf16().collect();
  assert_eq!(v, EXAMPLE);

  let v: Vec<u16> = "example".encode_utf16().chain(Some(0)).collect();
  assert_eq!(v, EXAMPLE_NULL);
  let v: Vec<u16> = "example\0".encode_utf16().collect();
  assert_eq!(v, EXAMPLE_NULL);

  // You don't even need to assign the output to a const.
  assert_eq!(utf16!("This works")[0], 'T' as u8 as u16);
}

No runtime deps