3 unstable releases

Uses old Rust 2015

0.2.1 Apr 12, 2020
0.2.0 Dec 30, 2019
0.1.0 Mar 18, 2018

#23 in #emit

Download history 10/week @ 2024-02-18 39/week @ 2024-02-25 13/week @ 2024-03-03 12/week @ 2024-03-10 15/week @ 2024-03-17 13/week @ 2024-03-24 187/week @ 2024-03-31 6/week @ 2024-04-07 9/week @ 2024-04-14 21/week @ 2024-04-21 14/week @ 2024-04-28 7/week @ 2024-05-05 11/week @ 2024-05-12

54 downloads per month
Used in tokengrams

MIT/Apache

6KB
106 lines

A rust prodedural macro that creates UTF-16 encoded literals (as &[u16; N])

#[macro_use]
extern crate utf16_literal;

extern "system" {
    fn MessageBoxW(*const (), *const u16, *const u16)
}

fn main() {
    let title = u16!("Rust Code\0");
    let msg = u16!("Hello World\0");
    unsafe {
        MessageBoxW(::std::ptr::null(), msg, title, 0);
    }
}

lib.rs:

This crate provides the utf16! macro, that takes a string literal and produces a &[u16; N] containing the UTF-16 encoded version of that string.

#![feature(proc_macro_hygiene)]	// Needed to use the macro in an expression
extern crate utf16_literal;

let v = utf16_literal::utf16!("Foo\u{1234}😀");
assert_eq!(v[0], 'F' as u16);
assert_eq!(v[1], 'o' as u16);
assert_eq!(v[2], 'o' as u16);
assert_eq!(v[3], 0x1234);
assert_eq!(v[4], 0xD83D);
assert_eq!(v[5], 0xDE00);
assert_eq!(v.len(), 6);

No runtime deps