#utf-16

utf16_lit

macro_rules to make utf-16 literals

8 releases (5 stable)

2.0.2 Feb 14, 2021
2.0.1 Feb 7, 2021
1.0.1 Sep 13, 2020
1.0.0 Jul 16, 2020
0.0.3 Mar 6, 2020

#369 in Text processing

Download history 20178/week @ 2024-06-14 27676/week @ 2024-06-21 21423/week @ 2024-06-28 19521/week @ 2024-07-05 30510/week @ 2024-07-12 24578/week @ 2024-07-19 25199/week @ 2024-07-26 19814/week @ 2024-08-02 16522/week @ 2024-08-09 17222/week @ 2024-08-16 19218/week @ 2024-08-23 17085/week @ 2024-08-30 19274/week @ 2024-09-06 15663/week @ 2024-09-13 22090/week @ 2024-09-20 13353/week @ 2024-09-27

74,464 downloads per month
Used in 62 crates (7 directly)

Zlib OR Apache-2.0 OR MIT

7KB
78 lines

License:Zlib min-rust crates.io docs.rs

utf16_lit

Provides a macro_rules to re-encode utf8 to utf16.


lib.rs:

Provides a macro_rules for making utf-16 literals.

Outputs are arrays of the correct size. Prefix the macro with & to make slices.

use utf16_lit::{utf16, utf16_null};

const EXAMPLE: &[u16] = &utf16!("example");

const EXAMPLE_NULL: &[u16] = &utf16_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);
  let v: Vec<u16> = "example\0".encode_utf16().collect();
  assert_eq!(v, EXAMPLE_NULL);

  // You don't even need to assign the output to a const.
  assert_eq!(utf16!("This works")[0], 'T' as u8 as u16);
}

No runtime deps