#string-literal #utf-16 #literals #u16 #macro #emit #encoded

utf16_literal

提供u16!宏,用于输出UTF-16字符串字面量

3个不稳定版本

使用旧的Rust 2015

0.2.1 2020年4月12日
0.2.0 2019年12月30日
0.1.0 2018年3月18日

#25#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 每月下载量
用于 tokengrams

MIT/Apache

6KB
106

一个Rust过程宏,用于创建UTF-16编码的常量(如&[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:

该包提供了utf16!宏,该宏接受一个字符串字面量并生成一个包含该字符串UTF-16编码版本的&[u16; N]。

#![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);

无运行时依赖