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
122 downloads per month
Used in tokengrams
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);