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

#25 in #u16

Download history 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 12/week @ 2024-05-19 19/week @ 2024-05-26 14/week @ 2024-06-02 19/week @ 2024-06-09 20/week @ 2024-06-16 20/week @ 2024-06-23 2/week @ 2024-06-30 35/week @ 2024-07-07 74/week @ 2024-07-14 10/week @ 2024-07-21

122 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