[][src]Crate utf16_lit

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

use utf16_lit::{utf16, utf16_null};
 
// must be an item!
utf16!(EXAMPLE, "example");
 
utf16_null!(EXAMPLE_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);
}

Currently "function-like" proc macros can't be used in expression or statement position, only item position. This means that the ergonomics of this proc-macro are quite poor at the moment. Once the proc-macro situation improves we can make this proc-macro more "natural" to use.

In the future I hope to slim it down so that it's just a string literal to &[u16] conversion, without needing to pass in idents to make constants or any of that.

Macros

utf16

Makes a &[u16] const.

utf16_null

Makes a &[u16] const with a null terminator.